aboutsummaryrefslogtreecommitdiff
path: root/src/moves.cpp
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/moves.cpp
parentd69c731bde5cf2c958c794f505684365072ab64a (diff)
optimazing the getlegal moves function
Diffstat (limited to 'src/moves.cpp')
-rw-r--r--src/moves.cpp8
1 files changed, 4 insertions, 4 deletions
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;