1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +00:00

Simplify Position::print()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-05-12 11:35:40 +01:00
parent c19a6ef82d
commit f86182e791

View file

@ -63,7 +63,7 @@ const Value PieceValueEndgame[17] = {
}; };
// To convert a Piece to and from a FEN char // 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 /// 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 sq += Square(token - '0'); // Advance the given number of files
else if (token == '/') else if (token == '/')
sq = make_square(FILE_A, rank_of(sq) - Rank(2)); sq -= Square(16);
else if ((p = PieceToChar.find(token)) != string::npos) else if ((p = PieceToChar.find(token)) != string::npos)
{ {
@ -319,7 +319,11 @@ const string Position::to_fen() const {
void Position::print(Move move) 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) if (move)
{ {
@ -327,22 +331,11 @@ void Position::print(Move move) const {
cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move); cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move);
} }
for (Rank rank = RANK_8; rank >= RANK_1; rank--) for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
{ if (piece_on(sq) != NO_PIECE)
cout << dottedLine << '|'; brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)];
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)) cout << brd << "\nFen is: " << to_fen() << "\nKey is: " << st->key << endl;
piece++; // Index the dot
cout << c << PieceToChar[piece] << c << '|';
}
}
cout << dottedLine << "Fen is: " << to_fen() << "\nKey is: " << st->key << endl;
} }