TextIO { public static String asciiBoard(Position pos) { StringBuilder ret = new StringBuilder(400); String nl = String.format(Locale.US, "%n"); ret.append(" +----+----+----+----+----+----+----+----+"); ret.append(nl); for (int y = 7; y >= 0; y--) { ret.append(" |"); for (int x = 0; x < 8; x++) { ret.append(' '); int p = pos.getPiece(Position.getSquare(x, y)); if (p == Piece.EMPTY) { boolean dark = Position.darkSquare(x, y); ret.append(dark ? ".. |" : " |"); } else { ret.append(Piece.isWhite(p) ? ' ' : '*'); String pieceName = pieceToChar(p); if (pieceName.length() == 0) pieceName = "P"; ret.append(pieceName); ret.append(" |"); } } ret.append(nl); ret.append(" +----+----+----+----+----+----+----+----+"); ret.append(nl); } return ret.toString(); }  static Position readFEN(String fen); static void fixupEPSquare(Position pos); static String toFEN(Position pos); static String moveToString(Position pos, Move move, boolean longForm); static String moveToUCIString(Move m); static Move uciStringToMove(String move); static Move stringToMove(Position pos, String strMove); static int getSquare(String s); static String squareToString(int square); static String asciiBoard(Position pos); static final String startPosFEN; }
@Test public void testAsciiBoard() throws ChessParseError { System.out.println("asciiBoard"); Position pos = TextIO.readFEN("r4rk1/2pn3p/2q1q1n1/8/2q2p2/6R1/p4PPP/1R4K1 b - - 0 1"); String aBrd = TextIO.asciiBoard(pos); assertEquals(12, aBrd.length() - aBrd.replaceAll("\\*", "").length()); assertEquals(3, aBrd.length() - aBrd.replaceAll("\\*Q", " ").length()); assertEquals(3, aBrd.length() - aBrd.replaceAll(" P", " ").length()); }