Add Special Patterns to RuleSet

This commit is contained in:
Unknown 2018-10-17 21:08:55 +02:00
parent e6e82f78f2
commit 6d7120650f

View file

@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
abstract class RuleSet { abstract class RuleSet {
int checkRange; int checkRange;
List<Pattern> patterns;
bool checkSurvival(int neighbors); bool checkSurvival(int neighbors);
bool checkBirth(int neighbors); bool checkBirth(int neighbors);
@ -20,6 +21,32 @@ class Pattern<Point> extends DelegatingList<Point> {
class GameOfLife implements RuleSet { class GameOfLife implements RuleSet {
int checkRange = 1; int checkRange = 1;
List<Pattern> patterns = [
// Two blocks, offset
// ##
// ##
Pattern("Blinker", [
Point(0, 0),
Point(1, 0),
Point(0, 1),
Point(1, 1),
Point(2, 2),
Point(3, 2),
Point(2, 3),
Point(3, 3)
]),
// A 'gliding' Spaceship
// #
// #
// ###
Pattern("SpaceShip", [
Point(1, 0),
Point(2, 1),
Point(2, 2),
Point(1, 2),
Point(0, 2),
])
];
bool checkSurvival(int neighbors) => bool checkSurvival(int neighbors) =>
neighbors == 2 || neighbors == 3 ? true : false; neighbors == 2 || neighbors == 3 ? true : false;