1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

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 <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-11-15 08:14:28 +01:00
parent 7000e100bd
commit 3c05bd70eb
2 changed files with 28 additions and 20 deletions

View file

@ -31,6 +31,7 @@
#include "movepick.h" #include "movepick.h"
#include "position.h" #include "position.h"
#include "psqtab.h" #include "psqtab.h"
#include "san.h"
#include "ucioption.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 /// Position::print() prints an ASCII representation of the position to
/// the standard output. /// the standard output. If a move is given then also the san is print.
void Position::print() const { void Position::print(Move m) 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--) { static const std::string pieceLetters = " PNBRQK PNBRQK .";
std::cout << "+---+---+---+---+---+---+---+---+\n";
for(File file = FILE_A; file <= FILE_H; file++) { std::cout << std::endl;
Square sq = make_square(file, rank); if (m != MOVE_NONE)
Piece piece = piece_on(sq); {
if(piece == EMPTY) Position p(*this);
std::cout << ((square_color(sq) == WHITE)? "| " : "| . "); std::cout << "Move is: " << move_to_san(p, m) << std::endl;
else
std::cout << pieceStrings[piece];
}
std::cout << "|\n";
} }
std::cout << "+---+---+---+---+---+---+---+---+\n"; for (Rank rank = RANK_8; rank >= RANK_1; rank--)
std::cout << to_fen() << std::endl; {
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 << "+---+---+---+---+---+---+---+---+" << std::endl;
std::cout << "Fen is: " << to_fen() << std::endl;
std::cout << key << std::endl; std::cout << key << std::endl;
} }

View file

@ -128,7 +128,7 @@ public:
// Text input/output // Text input/output
void from_fen(const std::string &fen); void from_fen(const std::string &fen);
const std::string to_fen() const; const std::string to_fen() const;
void print() const; void print(Move m = MOVE_NONE) const;
// Copying // Copying
void copy(const Position &pos); void copy(const Position &pos);