ascii property

String ascii

Returns a String representation of the current position complete with ascii art

Implementation

String get ascii {
  String s = '   +------------------------+\n';
  for (var i = SQUARES_A8; i <= SQUARES_H1; i++) {
    /* display the rank */
    if (file(i) == 0) {
      s += ' ' + '87654321'[rank(i)] + ' |';
    }

    /* empty piece */
    if (board[i] == null) {
      s += ' ' + ' . ' + ' ';
    } else {
      PieceType type = board[i]!.type;
      Color color = board[i]!.color;
      var symbol = (color == WHITE) ? type.toUpperCase() : type.toLowerCase();
      s += ' ' + symbol + ' ';
    }

    if (((i + 1) & 0x88) != 0) {
      s += '|\n';
      i += 8;
    }
  }
  s += '   +------------------------+\n';
  s += '     a  b  c  d  e  f  g  h\n';

  return s;
}