diff --git a/source/board.cpp b/source/board.cpp index 50e4a8c..4d41335 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -252,11 +252,11 @@ void Board::ResetMoves() { void Board::ListMoves() { int moveCount = 1; for (int i = 0; i < currentMoveIndex; i++) { - Board copy = *this; - bool isLegal = copy.MakeMove(moveList[i]); + if (IsLegal(moveList[i])) continue; + + Board copy = *this; + copy.MakeMove(moveList[i]); - if (!isLegal) - continue; std::cout << moveCount << ". "; moveList[i].PrintMove(); @@ -348,7 +348,7 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) { SetPiece(pieceType, square, color); } -bool Board::MakeMove(Move move) { +void Board::MakeMove(Move move) { // Null Move if (!move) { int newEpTarget = noEPTarget; @@ -362,7 +362,7 @@ bool Board::MakeMove(Move move) { enPassantTarget = newEpTarget; - return true; + return; } int newEpTarget = noEPTarget; @@ -505,8 +505,6 @@ bool Board::MakeMove(Move move) { } positionIndex++; - - return true; } bool Board::InPossibleZug() { diff --git a/source/board.h b/source/board.h index 4916472..6ecda1b 100644 --- a/source/board.h +++ b/source/board.h @@ -68,7 +68,7 @@ public: void RemovePiece(int piece, int square, bool color); void Promote(int square, int pieceType, int color, bool isCapture); - bool MakeMove(Move move); + void MakeMove(Move move); bool InPossibleZug(); diff --git a/source/datagen.cpp b/source/datagen.cpp index 8fc0c1c..dad1684 100644 --- a/source/datagen.cpp +++ b/source/datagen.cpp @@ -206,10 +206,11 @@ static bool IsGameOver(Board &board, SEARCH::SearchContext* ctx) { int moveSeen = 0; for (int i = 0; i < board.currentMoveIndex; i++) { - Board copy = board; - bool isLegal = copy.MakeMove(board.moveList[i]); - if (!isLegal) continue; + if (!board.IsLegal(board.moveList[i])) continue; + Board copy = board; + copy.MakeMove(board.moveList[i]); + moveSeen++; } @@ -227,12 +228,14 @@ static void PlayRandMoves(Board &board, SEARCH::SearchContext* ctx) { MOVEGEN::GenerateMoves(board, true); std::uniform_int_distribution dist(0, board.currentMoveIndex - 1); - bool isLegal = board.MakeMove(board.moveList[dist(rng)]); - if (!isLegal) { + Move currMove = board.moveList[dist(rng)]; + if (!board.IsLegal(currMove)) { count--; continue; } + board.MakeMove(currMove); + ctx->positionHistory[board.positionIndex] = board.hashKey; MOVEGEN::GenerateMoves(board, true); if (IsGameOver(board, ctx)) break; diff --git a/source/perft.cpp b/source/perft.cpp index fba548f..f1a7c51 100644 --- a/source/perft.cpp +++ b/source/perft.cpp @@ -29,9 +29,9 @@ void Perft(Board &board, int depth) { Stopwatch sw; for (int i = 0; i < board.currentMoveIndex; i++) { + if (!board.IsLegal(board.moveList[i])) continue; Board copy = board; - bool isLegal = copy.MakeMove(board.moveList[i]); - if (!isLegal) continue; + copy.MakeMove(board.moveList[i]); U64 nodeCount = HelperPerft(copy, depth - 1); totalNodes += nodeCount; board.moveList[i].PrintMove();