55 lines
1.1 KiB
Dart
55 lines
1.1 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
abstract class RuleSet {
|
|
int checkRange;
|
|
List<Pattern> patterns;
|
|
|
|
bool checkSurvival(int neighbors);
|
|
bool checkBirth(int neighbors);
|
|
}
|
|
|
|
class Pattern<Point> extends DelegatingList<Point> {
|
|
final String _name;
|
|
Pattern(String name, List base)
|
|
: _name = name,
|
|
super(base);
|
|
|
|
String get name => _name;
|
|
}
|
|
|
|
class GameOfLife implements RuleSet {
|
|
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) =>
|
|
neighbors == 2 || neighbors == 3 ? true : false;
|
|
bool checkBirth(int neighbors) => neighbors == 3 ? true : false;
|
|
}
|