From ca5e947269608757a1af5295f5c77958de341fc3 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 28 Jul 2026 09:43:30 +0200 Subject: making bot do check and add knight table --- src/moves.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/moves.cpp') diff --git a/src/moves.cpp b/src/moves.cpp index 5401e8b..d7df595 100644 --- a/src/moves.cpp +++ b/src/moves.cpp @@ -123,6 +123,36 @@ std::vector GetPseudoLegalMoves(Game *b) { return moves; } +bool IsSquareAttacked(Game *board, Position square, bool white) { + Game temp = *board; + + // Generate moves for the attacking side + temp.turn = white; + + auto moves = GetPseudoLegalMoves(&temp); + + for (const Move &move : moves) { + if (move.To == square) + return true; + } + + return false; +} +bool IsPieceTypeAttacked(Game *board, PieceType type, bool white) { + Game temp = *board; + + // Generate moves for the attacking side + temp.turn = white; + + auto moves = GetPseudoLegalMoves(&temp); + + for (const Move &move : moves) { + if (temp.pieces[PositionToIndex(move.To)].type == type) + return true; + } + + return false; +} std::vector GetLegalMoves(Game *b) { std::vector moves = GetPseudoLegalMoves(b); std::vector legalMove; -- cgit v1.2.3