[Board] Implement stream operator
This commit is contained in:
21
Board.cpp
21
Board.cpp
@@ -71,6 +71,25 @@ void Board::pseudoLegalMovesFrom(const Square &from,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const Board &board) {
|
std::ostream &operator<<(std::ostream &os, const Board &board) {
|
||||||
(void) board;
|
// For debugging only, performance isn't important
|
||||||
|
for (int i = 63; i >= 0; i--) {
|
||||||
|
// Get the piece for this index. Assume it exists.
|
||||||
|
auto piece = board.piece(Square::fromIndex(i).value());
|
||||||
|
|
||||||
|
// Print piece, otherwise '.';
|
||||||
|
if (piece.has_value()) {
|
||||||
|
os << piece.value();
|
||||||
|
} else {
|
||||||
|
os << '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a file is done, output newline
|
||||||
|
if (i % 8 == 0) {
|
||||||
|
os << '\n';
|
||||||
|
} else {
|
||||||
|
os << ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user