cleanup | bench 1812688

This commit is contained in:
rektdie committed 2026-02-19 15:12:17 +01:00
1 parent a9b51e384f
commit 320c43cdd3
4 files changed
+17 -16

No files matched your search

+6 -8
View File
@@ -252,11 +252,11 @@ void Board::ResetMoves() {
void Board::ListMoves() { void Board::ListMoves() {
int moveCount = 1; int moveCount = 1;
for (int i = 0; i < currentMoveIndex; i++) { for (int i = 0; i < currentMoveIndex; i++) {
Board copy = *this; if (IsLegal(moveList[i])) continue;
bool isLegal = copy.MakeMove(moveList[i]);
Board copy = *this;
copy.MakeMove(moveList[i]);
if (!isLegal)
continue;
std::cout << moveCount << ". "; std::cout << moveCount << ". ";
moveList[i].PrintMove(); moveList[i].PrintMove();
@@ -348,7 +348,7 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) {
SetPiece(pieceType, square, color); SetPiece(pieceType, square, color);
} }
bool Board::MakeMove(Move move) { void Board::MakeMove(Move move) {
// Null Move // Null Move
if (!move) { if (!move) {
int newEpTarget = noEPTarget; int newEpTarget = noEPTarget;
@@ -362,7 +362,7 @@ bool Board::MakeMove(Move move) {
enPassantTarget = newEpTarget; enPassantTarget = newEpTarget;
return true; return;
} }
int newEpTarget = noEPTarget; int newEpTarget = noEPTarget;
@@ -505,8 +505,6 @@ bool Board::MakeMove(Move move) {
} }
positionIndex++; positionIndex++;
return true;
} }
bool Board::InPossibleZug() { bool Board::InPossibleZug() {
+1 -1
View File
@@ -68,7 +68,7 @@ public:
void RemovePiece(int piece, int square, bool color); void RemovePiece(int piece, int square, bool color);
void Promote(int square, int pieceType, int color, bool isCapture); void Promote(int square, int pieceType, int color, bool isCapture);
bool MakeMove(Move move); void MakeMove(Move move);
bool InPossibleZug(); bool InPossibleZug();
+8 -5
View File
@@ -206,10 +206,11 @@ static bool IsGameOver(Board &board, SEARCH::SearchContext* ctx) {
int moveSeen = 0; int moveSeen = 0;
for (int i = 0; i < board.currentMoveIndex; i++) { 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++; moveSeen++;
} }
@@ -227,12 +228,14 @@ static void PlayRandMoves(Board &board, SEARCH::SearchContext* ctx) {
MOVEGEN::GenerateMoves<All>(board, true); MOVEGEN::GenerateMoves<All>(board, true);
std::uniform_int_distribution<int> dist(0, board.currentMoveIndex - 1); std::uniform_int_distribution<int> 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--; count--;
continue; continue;
} }
board.MakeMove(currMove);
ctx->positionHistory[board.positionIndex] = board.hashKey; ctx->positionHistory[board.positionIndex] = board.hashKey;
MOVEGEN::GenerateMoves<All>(board, true); MOVEGEN::GenerateMoves<All>(board, true);
if (IsGameOver(board, ctx)) break; if (IsGameOver(board, ctx)) break;
+2 -2
View File
@@ -29,9 +29,9 @@ void Perft(Board &board, int depth) {
Stopwatch sw; Stopwatch sw;
for (int i = 0; i < board.currentMoveIndex; i++) { for (int i = 0; i < board.currentMoveIndex; i++) {
if (!board.IsLegal(board.moveList[i])) continue;
Board copy = board; Board copy = board;
bool isLegal = copy.MakeMove(board.moveList[i]); copy.MakeMove(board.moveList[i]);
if (!isLegal) continue;
U64 nodeCount = HelperPerft(copy, depth - 1); U64 nodeCount = HelperPerft(copy, depth - 1);
totalNodes += nodeCount; totalNodes += nodeCount;
board.moveList[i].PrintMove(); board.moveList[i].PrintMove();