From 530b81fb80159b68598d4b974924d2206f7c9d6a Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 28 Jul 2026 14:18:11 +0200 Subject: optimazing the getlegal moves function --- src/bot.cpp | 2 +- src/moves.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/bot.cpp b/src/bot.cpp index c8842bd..4137f05 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -57,7 +57,7 @@ int ROOK_TABLE[64] = { 0, 0, 5, 10, 10, 5, 0, 0, // }; -const int SEARCH_DEPTH = 5; +const int SEARCH_DEPTH = 4; #include diff --git a/src/moves.cpp b/src/moves.cpp index bba85e7..664971d 100644 --- a/src/moves.cpp +++ b/src/moves.cpp @@ -174,17 +174,17 @@ std::vector GetLegalMoves(Game *b) { std::vector legalMove; for (Move move : moves) { bool isLegal = true; - Game testBoard = *b; - PlayMove(move, &testBoard); - auto opponentResponse = GetPseudoLegalMoves(&testBoard); + UndoMove undo = MakeMove(move, b); + auto opponentResponse = GetPseudoLegalMoves(b); for (Move move : opponentResponse) { - if (testBoard.pieces[PositionToIndex(move.To)].type == KING) { + if (b->pieces[PositionToIndex(move.To)].type == KING) { isLegal = false; } } if (isLegal) { legalMove.push_back(move); }; + UnMake(undo, b); } if (legalMove.size() == 0) { bool isCheck = false; -- cgit v1.2.3