[Board] Implement stream operator

This commit is contained in:
2022-12-21 10:04:55 +01:00
parent 48fd630204
commit a78f3ee516

View File

@@ -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;
} }