Add fast Board::IsLegal move validation
This commit is contained in:
1 parent
0f748da56c
commit
a9f466b37b
5 files changed
+694
-602
No files matched your search
+8
-4
@@ -10,9 +10,11 @@ static U64 HelperPerft(Board board, int depth) {
|
||||
U64 nodes = 0;
|
||||
|
||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||
Move move = board.moveList[i];
|
||||
if (!board.IsLegal(move)) continue;
|
||||
|
||||
Board copy = board;
|
||||
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||
if (!isLegal) continue;
|
||||
copy.MakeMove(move);
|
||||
nodes += HelperPerft(copy, depth - 1);
|
||||
}
|
||||
return nodes;
|
||||
@@ -25,9 +27,11 @@ void Perft(Board &board, int depth) {
|
||||
|
||||
Stopwatch sw;
|
||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||
Move move = board.moveList[i];
|
||||
if (!board.IsLegal(move)) continue;
|
||||
|
||||
Board copy = board;
|
||||
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||
if (!isLegal) continue;
|
||||
copy.MakeMove(move);
|
||||
U64 nodeCount = HelperPerft(copy, depth - 1);
|
||||
totalNodes += nodeCount;
|
||||
board.moveList[i].PrintMove();
|
||||
|
||||
Reference in new issue
Block a user