asString method

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

Returns the GridWorld as an ANSI animation.

Implementation

@override
String asString(GridWorld w) {
  // Move cursor up.
  // ignore: avoid_print
  print('$_csi${w.nRows + 2}A');
  final lines = StringBuffer();
  for (var i = 0; i < w.nRows; i++) {
    final sb = StringBuffer();
    for (var j = 0; j < w.nCols; j++) {
      sb.write(w.isAlive(i, j) ? _fancyAlive : _fancyDead);
    }
    lines.writeln(sb);
  }
  lines.write(_csiReset);
  return lines.toString();
}