asString method

  1. @override
String asString(
  1. GridWorld w
)
override

Returns the GridWorld as a string with nRows lines and nCols columns.

Implementation

@override
String asString(GridWorld w) {
  final lines = StringBuffer();
  for (var i = 0; i < w.nRows; i++) {
    final sb = StringBuffer();
    for (var j = 0; j < w.nCols; j++) {
      sb.writeCharCode(
          w.isAlive(i, j) ? GridWorld.chAlive : GridWorld.chDead);
    }
    lines.writeln(sb);
  }
  return lines.toString();
}