From 3c05bd70ebf57cebb88d29a88e6c492976a97761 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 15 Nov 2008 08:14:28 +0100 Subject: [PATCH] Print the move in addition to position Teach Position::print() to optionally print a given move in san notation in addition to the ASCII representation of the board. Signed-off-by: Marco Costalba --- src/position.cpp | 50 ++++++++++++++++++++++++++++-------------------- src/position.h | 2 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 958a9397..8390facc 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -31,6 +31,7 @@ #include "movepick.h" #include "position.h" #include "psqtab.h" +#include "san.h" #include "ucioption.h" @@ -263,28 +264,35 @@ const std::string Position::to_fen() const { /// Position::print() prints an ASCII representation of the position to -/// the standard output. - -void Position::print() const { - char pieceStrings[][8] = - {"| ? ", "| P ", "| N ", "| B ", "| R ", "| Q ", "| K ", "| ? ", - "| ? ", "|=P=", "|=N=", "|=B=", "|=R=", "|=Q=", "|=K=" - }; - - for(Rank rank = RANK_8; rank >= RANK_1; rank--) { - std::cout << "+---+---+---+---+---+---+---+---+\n"; - for(File file = FILE_A; file <= FILE_H; file++) { - Square sq = make_square(file, rank); - Piece piece = piece_on(sq); - if(piece == EMPTY) - std::cout << ((square_color(sq) == WHITE)? "| " : "| . "); - else - std::cout << pieceStrings[piece]; - } - std::cout << "|\n"; +/// the standard output. If a move is given then also the san is print. + +void Position::print(Move m) const { + + static const std::string pieceLetters = " PNBRQK PNBRQK ."; + + std::cout << std::endl; + if (m != MOVE_NONE) + { + Position p(*this); + std::cout << "Move is: " << move_to_san(p, m) << std::endl; + } + for (Rank rank = RANK_8; rank >= RANK_1; rank--) + { + std::cout << "+---+---+---+---+---+---+---+---+" << std::endl; + for (File file = FILE_A; file <= FILE_H; file++) + { + Square sq = make_square(file, rank); + Piece piece = piece_on(sq); + if (piece == EMPTY && square_color(sq) == WHITE) + piece = NO_PIECE; + + char col = (color_of_piece_on(sq) == BLACK ? '=' : ' '); + std::cout << '|' << col << pieceLetters[piece] << col; + } + std::cout << '|' << std::endl; } - std::cout << "+---+---+---+---+---+---+---+---+\n"; - std::cout << to_fen() << std::endl; + std::cout << "+---+---+---+---+---+---+---+---+" << std::endl; + std::cout << "Fen is: " << to_fen() << std::endl; std::cout << key << std::endl; } diff --git a/src/position.h b/src/position.h index 27ec25a7..6076a539 100644 --- a/src/position.h +++ b/src/position.h @@ -128,7 +128,7 @@ public: // Text input/output void from_fen(const std::string &fen); const std::string to_fen() const; - void print() const; + void print(Move m = MOVE_NONE) const; // Copying void copy(const Position &pos); -- 2.39.2