[Board] Add method to print BitBoard

This commit is contained in:
2022-12-21 20:04:22 +01:00
parent 4671fec523
commit 16c7fe2a34
2 changed files with 20 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
#include <cmath>
#include <bitset>
#include <algorithm>
#include <iostream>
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

View File

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