aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-28 14:18:11 +0200
committerAdam <adammegarules1@gmail.com>2026-07-28 14:18:11 +0200
commit530b81fb80159b68598d4b974924d2206f7c9d6a (patch)
tree6b5029872239e179fc6299f08f39881e919f2729 /src
parentd69c731bde5cf2c958c794f505684365072ab64a (diff)
optimazing the getlegal moves function
Diffstat (limited to 'src')
-rw-r--r--src/bot.cpp2
-rw-r--r--src/moves.cpp8
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;