grid_world 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

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.

1.0.1 #

  • Typo, blah

1.0.0 #

  • Fix lints, start stable release.

0.1.10 #

  • Fix readme.

0.1.9 #

  • Fix package description.

0.1.8 #

  • Nope!

0.1.7 #

  • Add a bin directory, symlinked to example, see if it works under 'pub global run'.

0.1.6 #

  • Add expandToFit.

0.1.5 #

  • Add GridWorldIterable.

0.1.4 #

  • Add copy, tbPadded, lrPadded.

0.1.3 #

  • Add hashcode and equals to GridWorld.

0.1.2 #

  • Remove extraneous linefeed from movie.

0.1.1 #

  • Fix some formatting in docs, add movie method to GridWorld.

0.1.0 #

  • Release v0.1.0 because why not?

0.0.3 #

  • Fix documentation nits.

0.0.2 #

  • Fix nits found by dartanalyzer.

0.0.1 #

  • Initial version, to learn dart

example/main.dart

import 'dart:io';
import 'package:grid_world/grid_world.dart';

/// Make room on terminal for ANSI painting.
void clearScreen(GridWorld w) {
  for (var i = 0; i < w.nRows + 2; i++) {
    // ignore: avoid_print
    print('');
  }
}

/// Tuple of a step count and a world.
class Tup {
  Tup(this.numSteps, this.w);
  final int numSteps;
  final GridWorld w;
}

/// Demo various Conway Game of Life patterns.
void main() {
  final str = GridStringerAnsi();
  const pause = Duration(milliseconds: 100);

  for (final tup in [
    Tup(30, ConwayEvolver.blinker),
    Tup(40, ConwayEvolver.toad),
    Tup(45, ConwayEvolver.pentaDecathlon.clockwise90()),
    Tup(60, ConwayEvolver.lightweightSpaceship.padRight(30).padBottom(1)),
    Tup(60, ConwayEvolver.glider.padRight(22).padBottom(20)),
    Tup(80, ConwayEvolver.gliderFleet()),
    Tup(100, ConwayEvolver.gunFight()),
    Tup(1000, ConwayEvolver.rPentimino.padded(30)),
  ]) {
    clearScreen(tup.w);
    for (final w in GridWorldIterable(tup.w, limit: tup.numSteps)) {
      // ignore: avoid_print
      print(str.asString(w));
      sleep(pause);
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  grid_world: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:grid_world/grid_world.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
27
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
test ^1.9.4 1.15.2
tuple ^1.0.3 1.0.3
Transitive dependencies
_fe_analyzer_shared 5.0.0
analyzer 0.39.12
args 1.6.0
async 2.4.2
boolean_selector 2.0.0
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
coverage 0.14.0
crypto 2.1.5
csslib 0.16.1
glob 1.2.0
html 0.14.0+3
http 0.12.1
http_multi_server 2.2.0
http_parser 3.1.4
io 0.3.4
js 0.6.2
logging 0.11.4
matcher 0.12.8
meta 1.2.2 1.3.0-nullsafety
mime 0.9.6+3
node_interop 1.1.1
node_io 1.1.1
node_preamble 1.4.12
package_config 1.9.3
path 1.7.0
pool 1.4.0
pub_semver 1.4.4
quiver 2.1.3
shelf 0.7.7
shelf_packages_handler 2.0.0
shelf_static 0.2.8
shelf_web_socket 0.2.3
source_map_stack_trace 2.0.0
source_maps 0.10.9
source_span 1.7.0
stack_trace 1.9.5
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
test_api 0.2.17
test_core 0.3.10
typed_data 1.2.0 1.3.0-nullsafety
vm_service 4.1.0
watcher 0.9.7+15
web_socket_channel 1.1.0
webkit_inspection_protocol 0.7.3
yaml 2.2.1
Dev dependencies
pedantic ^1.0.0 1.9.2