From 16c7fe2a34a846b57a5fe7c4a705e921be31bf70 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Wed, 21 Dec 2022 20:04:22 +0100 Subject: [PATCH] [Board] Add method to print BitBoard --- Board.cpp | 19 +++++++++++++++++++ Board.hpp | 1 + 2 files changed, 20 insertions(+) diff --git a/Board.cpp b/Board.cpp index 2d5ad38..b5c593c 100644 --- a/Board.cpp +++ b/Board.cpp @@ -5,6 +5,7 @@ #include #include #include +#include Board::Board() { } @@ -197,6 +198,24 @@ bool Board::isMoveCastling(const BitBoard &from, const BitBoard &to, const Piece return (from & indexToBitBoard(E8)); } +void Board::printBitBoard(const Board::BitBoard &bb) { + // For debugging only, performance isn't important + for (int i = 7; i >= 0; i--) { + int rank = i * 8; + for (int j = 0; j < 8; j++) { + // Get the piece for this index. Assume it exists. + // Print piece, otherwise '.'; + if (bb & (1ULL << (rank + j))) { + std::cout << 1; + } else { + std::cout << '.'; + } + + std::cout << ' '; + } + std::cout << '\n'; + } +} std::ostream &operator<<(std::ostream &os, const Board &board) { // For debugging only, performance isn't important diff --git a/Board.hpp b/Board.hpp index c35b690..7755b5e 100644 --- a/Board.hpp +++ b/Board.hpp @@ -127,6 +127,7 @@ private: return __builtin_ctzll(b); } + static void printBitBoard(const BitBoard &bb); void handlePawnDoubleAdvance(const Move &move, BitBoard bb, const Piece &movedPiece); void handleEnPassant(const Move &move, const Piece &movedPiece); };