From f86182e791d0ff9d490556a06f9ae3f8770ff55d Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 12 May 2012 11:35:40 +0100 Subject: [PATCH 1/1] Simplify Position::print() No functional change. Signed-off-by: Marco Costalba --- src/position.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 95195d3a..fd7b1ba2 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -63,7 +63,7 @@ const Value PieceValueEndgame[17] = { }; // To convert a Piece to and from a FEN char -static const string PieceToChar(" PNBRQK pnbrqk ."); +static const string PieceToChar(" PNBRQK pnbrqk"); /// CheckInfo c'tor @@ -154,7 +154,7 @@ void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) { sq += Square(token - '0'); // Advance the given number of files else if (token == '/') - sq = make_square(FILE_A, rank_of(sq) - Rank(2)); + sq -= Square(16); else if ((p = PieceToChar.find(token)) != string::npos) { @@ -319,7 +319,11 @@ const string Position::to_fen() const { void Position::print(Move move) const { - const char* dottedLine = "\n+---+---+---+---+---+---+---+---+\n"; + const string dottedLine = "\n+---+---+---+---+---+---+---+---+"; + const string twoRows = dottedLine + "\n| | . | | . | | . | | . |" + + dottedLine + "\n| . | | . | | . | | . | |"; + + string brd = twoRows + twoRows + twoRows + twoRows + dottedLine; if (move) { @@ -327,22 +331,11 @@ void Position::print(Move move) const { cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move); } - for (Rank rank = RANK_8; rank >= RANK_1; rank--) - { - cout << dottedLine << '|'; - for (File file = FILE_A; file <= FILE_H; file++) - { - Square sq = make_square(file, rank); - Piece piece = piece_on(sq); - char c = (color_of(piece) == BLACK ? '=' : ' '); - - if (piece == NO_PIECE && !opposite_colors(sq, SQ_A1)) - piece++; // Index the dot + for (Square sq = SQ_A1; sq <= SQ_H8; sq++) + if (piece_on(sq) != NO_PIECE) + brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)]; - cout << c << PieceToChar[piece] << c << '|'; - } - } - cout << dottedLine << "Fen is: " << to_fen() << "\nKey is: " << st->key << endl; + cout << brd << "\nFen is: " << to_fen() << "\nKey is: " << st->key << endl; } -- 2.39.2