Revert "encapsulated positionHistory | bench 1857933"

This reverts commit 2e8c23103f.
This commit is contained in:
rektdie committed 2025-04-12 10:58:56 +02:00
1 parent ce02841a5c
commit 3275cee01e
6 files changed
+37 -34

No files matched your search

+2
View File
@@ -65,6 +65,7 @@ void RunBenchmark() {
Board board; Board board;
int depth = BENCH_DEPTH; int depth = BENCH_DEPTH;
int ply = 0; int ply = 0;
board.positionIndex = 0;
// Clearing // Clearing
TT.Clear(); TT.Clear();
@@ -80,4 +81,5 @@ void RunBenchmark() {
std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl; std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl;
TT.Clear(); TT.Clear();
board.positionIndex = 0;
} }
+26
View File
@@ -393,6 +393,7 @@ bool Board::MakeMove(Move move) {
} }
positionIndex++; positionIndex++;
positionHistory[positionIndex] = hashKey;
return true; return true;
} }
@@ -443,3 +444,28 @@ void Board::ResetAccPair() {
blackPieces.PopBit(square); blackPieces.PopBit(square);
} }
} }
static bool IsThreefold(Board& board) {
for (int i = 0; i < board.positionIndex; i++) {
if (positionHistory[i] == board.hashKey) {
// repetition found
return true;
}
}
// no repetition
return false;
}
static bool IsFifty(Board& board) {
return (board.halfMoves >= 100);
}
static bool IsInsuffMat(Board& board) {
return (board.occupied.PopCount() <= 3
&& !(board.pieces[Pawn] | board.pieces[Queen] | board.pieces[Rook]));
}
bool Board::IsDraw() {
return IsFifty(*this) || IsInsuffMat(*this) || IsThreefold(*this);
}
+4
View File
@@ -10,6 +10,8 @@ constexpr int noEPTarget = -1;
constexpr int MAX_MOVES = 218; constexpr int MAX_MOVES = 218;
inline U64 positionHistory[1000];
class Board { class Board {
public: public:
Board() { Board() {
@@ -65,4 +67,6 @@ public:
bool MakeMove(Move move); bool MakeMove(Move move);
bool InPossibleZug(); bool InPossibleZug();
bool IsDraw();
}; };
+3 -3
View File
@@ -62,8 +62,8 @@ static void PlayRandMoves(Board &board) {
MOVEGEN::GenerateMoves<All>(board); MOVEGEN::GenerateMoves<All>(board);
} }
static bool IsGameOver(Board &board, SEARCH::SearchContext& ctx) { static bool IsGameOver(Board &board) {
if (SEARCH::IsDraw(board, ctx)) return true; if (board.IsDraw()) return true;
int moveSeen = 0; int moveSeen = 0;
@@ -106,7 +106,7 @@ void PlayGame(std::atomic<int>& positions, U64 targetPositions, std::vector<Game
SEARCH::SearchResults safeResults; SEARCH::SearchResults safeResults;
MOVEGEN::GenerateMoves<All>(board); MOVEGEN::GenerateMoves<All>(board);
while (!IsGameOver(board, ctx)) { while (!IsGameOver(board)) {
SEARCH::SearchResults results = SEARCH::SearchPosition<SEARCH::datagen>(board, SearchParams(), ctx); SEARCH::SearchResults results = SEARCH::SearchPosition<SEARCH::datagen>(board, SearchParams(), ctx);
if (!results.bestMove) break; if (!results.bestMove) break;
+1 -28
View File
@@ -92,31 +92,6 @@ void ListScores(Board &board, int ply, SearchContext& ctx) {
} }
} }
static bool IsThreefold(Board& board, SearchContext& ctx) {
for (int i = 0; i < board.positionIndex; i++) {
if (ctx.positionHistory[i] == board.hashKey) {
// repetition found
return true;
}
}
// no repetition
return false;
}
static bool IsFifty(Board& board) {
return (board.halfMoves >= 100);
}
static bool IsInsuffMat(Board& board) {
return (board.occupied.PopCount() <= 3
&& !(board.pieces[Pawn] | board.pieces[Queen] | board.pieces[Rook]));
}
static bool IsDraw(Board &board, SearchContext& ctx) {
return IsFifty(board) || IsInsuffMat(board) || IsThreefold(board, ctx);
}
static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) { static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) {
int reduction = 0; int reduction = 0;
@@ -172,7 +147,6 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc
Board copy = board; Board copy = board;
int isLegal = copy.MakeMove(board.moveList[i]); int isLegal = copy.MakeMove(board.moveList[i]);
if (!isLegal) continue; if (!isLegal) continue;
ctx.positionHistory[copy.positionIndex] = copy.hashKey;
ctx.nodes++; ctx.nodes++;
int score = -Quiescence<mode>(copy, -beta, -alpha, ply + 1, ctx).score; int score = -Quiescence<mode>(copy, -beta, -alpha, ply + 1, ctx).score;
@@ -217,7 +191,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
} }
ctx.pvLine.SetLength(ply); ctx.pvLine.SetLength(ply);
if (ply && (IsDraw(board, ctx))) return 0; if (ply && (board.IsDraw())) return 0;
// if NOT PV node then we try to hit the TTable // if NOT PV node then we try to hit the TTable
@@ -287,7 +261,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
bool isLegal = copy.MakeMove(currMove); bool isLegal = copy.MakeMove(currMove);
if (!isLegal) continue; if (!isLegal) continue;
ctx.positionHistory[copy.positionIndex] = copy.hashKey;
ctx.nodes++; ctx.nodes++;
int reductions = GetReductions(board, currMove, depth, moveSeen, ply); int reductions = GetReductions(board, currMove, depth, moveSeen, ply);
+1 -3
View File
@@ -113,7 +113,6 @@ public:
History history; History history;
std::array<std::array<int, MAX_PLY>, 2> killerMoves{}; std::array<std::array<int, MAX_PLY>, 2> killerMoves{};
std::array<U64, 1000> positionHistory;
Stopwatch sw; Stopwatch sw;
@@ -122,7 +121,6 @@ public:
history.Clear(); history.Clear();
sw.Restart(); sw.Restart();
killerMoves = {}; killerMoves = {};
positionHistory = {};
} }
}; };
@@ -132,7 +130,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
template <searchMode mode> template <searchMode mode>
SearchResults SearchPosition(Board &board, SearchParams params, SearchContext& ctx); SearchResults SearchPosition(Board &board, SearchParams params, SearchContext& ctx);
bool IsDraw(Board &board, SearchContext& ctx); bool IsDraw(Board &board);
constexpr int moveScoreTable[6][6] = { constexpr int moveScoreTable[6][6] = {
105, 205, 305, 405, 505, 605, 105, 205, 305, 405, 505, 605,