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 /src/moves.cpp | |
| parent | d69c731bde5cf2c958c794f505684365072ab64a (diff) | |
optimazing the getlegal moves function
Diffstat (limited to 'src/moves.cpp')
| -rw-r--r-- | src/moves.cpp | 8 |
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; |
