diff options
| author | Adam <adammegarules1@gmail.com> | 2026-07-28 14:18:11 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-07-28 14:18:11 +0200 |
| commit | 530b81fb80159b68598d4b974924d2206f7c9d6a (patch) | |
| tree | 6b5029872239e179fc6299f08f39881e919f2729 | |
| parent | d69c731bde5cf2c958c794f505684365072ab64a (diff) | |
optimazing the getlegal moves function
| -rw-r--r-- | src/bot.cpp | 2 | ||||
| -rw-r--r-- | src/moves.cpp | 8 |
2 files changed, 5 insertions, 5 deletions
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 <fstream> 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<Move> GetLegalMoves(Game *b) { std::vector<Move> 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; |
