introduced basic InCheck and IsLegal

This commit is contained in:
rektdie committed 2025-03-24 16:45:27 +01:00
1 parent d0ba47c956
commit 2943fccce6
4 files changed
+25 -9

No files matched your search

+17 -3
View File
@@ -132,6 +132,7 @@ void Board::ListMoves() {
for (int i = 0; i < currentMoveIndex; i++) {
std::cout << i+1 << ". ";
moveList[i].PrintMove();
std::cout << "( " << moveTypes[moveList[i].GetFlags()] << " )";
std::cout << std::endl;
}
}
@@ -149,11 +150,24 @@ int Board::GetPieceColor(int square) {
}
bool Board::InCheck() {
// TODO
int kingSquare = (pieces[King] & colors[sideToMove]).getLS1BIndex();
for (int type = Pawn; type <= Queen; type++) {
Bitboard moves = MOVEGEN::getPieceAttacks(kingSquare, type, sideToMove, occupied);
if (moves & colors[!sideToMove] & pieces[type]) return true;
}
return false;
}
bool Board::IsLegal(Move &move) {
// TODO
bool Board::IsLegal(Move move) {
Board copy = *this;
copy.MakeMove(move);
copy.sideToMove = sideToMove;
positionIndex--;
return !copy.InCheck();
}
void Board::SetPiece(int piece, int square, bool color) {