grid_world 1.0.1 grid_world: ^1.0.1 copied to clipboard
A cellular automaton library associated with a square grid. Includes Conway's Game of Life.
GridWorld #
GridWorld is a cellular automaton library associated with a square grid.
It includes Conway's Game of Life evolution rules, and some classic Conway patterns ready for injection.
git clone git@github.com:monopole/grid_world.git
cd grid_world
pub run test
dart example/main.dart
Primary interfaces #
GridWorld
#
A GridWorld
is a grid of cells that can be dead or alive.
A GridWorld
can be constructed from
-
a multi-line string, e.g.
final blinker = GridWorld.fromString(''' ..... ..#.. ..#.. ..#.. ..... ''');
where
.
means dead, and anything else means alive. -
other worlds pasted into or appended to each other.
The cells have no builtin rules regarding their evolution.
Evolver
#
A GridWorld
accepts an Evolver
to push it
through discrete evolutionary steps.
A ConwayEvolver
is an Evolver
embodying Conway's
GOL rules with wrap-around boundary conditions.
This evolver defines some static instances of
small GridWorlds
containing famous Conway GOL
patterns, e.g. the Gosper glider gun:
static final gosperGliderGun = GridWorld.fromString('''
......................................
.........................#............
.......................#.#............
.............##......##............##.
............#...#....##............##.
.##........#.....#...##...............
.##........#...#.##....#.#............
...........#.....#.......#............
............#...#.....................
.............##.......................
......................................
''');
GridWorldIterable
#
Extending Iterable<GridWorld>
, this object combines a GridWorld
and
an Evolver
such that one may evolve a world in an iteration context, e.g.
for (var w in GridWorldIterable(initialWorld, limit: 1000)) {
render(w);
}
GridStringer
#
A GridWorld
can be converted to a string using
a GridStringer
.
GridStringerAnsi
is a GridStringer
that converts a world
to a string with embedded ANSI escape sequences for
animation on a terminal.