encapsulated positionHistory | bench 1857933
This commit is contained in:
1 parent
aa0d34eb8e
commit
2e8c23103f
6 files changed
+34
-37
No files matched your search
@@ -65,7 +65,6 @@ void RunBenchmark() {
|
||||
Board board;
|
||||
int depth = BENCH_DEPTH;
|
||||
int ply = 0;
|
||||
board.positionIndex = 0;
|
||||
|
||||
// Clearing
|
||||
TT.Clear();
|
||||
@@ -81,5 +80,4 @@ void RunBenchmark() {
|
||||
|
||||
std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl;
|
||||
TT.Clear();
|
||||
board.positionIndex = 0;
|
||||
}
|
||||
@@ -393,7 +393,6 @@ bool Board::MakeMove(Move move) {
|
||||
}
|
||||
|
||||
positionIndex++;
|
||||
positionHistory[positionIndex] = hashKey;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -444,28 +443,3 @@ void Board::ResetAccPair() {
|
||||
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);
|
||||
}
|
||||
@@ -10,8 +10,6 @@ constexpr int noEPTarget = -1;
|
||||
|
||||
constexpr int MAX_MOVES = 218;
|
||||
|
||||
inline U64 positionHistory[1000];
|
||||
|
||||
class Board {
|
||||
public:
|
||||
Board() {
|
||||
@@ -67,6 +65,4 @@ public:
|
||||
bool MakeMove(Move move);
|
||||
|
||||
bool InPossibleZug();
|
||||
|
||||
bool IsDraw();
|
||||
};
|
||||
+3
-3
@@ -62,8 +62,8 @@ static void PlayRandMoves(Board &board) {
|
||||
MOVEGEN::GenerateMoves<All>(board);
|
||||
}
|
||||
|
||||
static bool IsGameOver(Board &board) {
|
||||
if (board.IsDraw()) return true;
|
||||
static bool IsGameOver(Board &board, SEARCH::SearchContext& ctx) {
|
||||
if (SEARCH::IsDraw(board, ctx)) return true;
|
||||
|
||||
int moveSeen = 0;
|
||||
|
||||
@@ -106,7 +106,7 @@ void PlayGame(std::atomic<int>& positions, U64 targetPositions, std::vector<Game
|
||||
SEARCH::SearchResults safeResults;
|
||||
MOVEGEN::GenerateMoves<All>(board);
|
||||
|
||||
while (!IsGameOver(board)) {
|
||||
while (!IsGameOver(board, ctx)) {
|
||||
SEARCH::SearchResults results = SEARCH::SearchPosition<SEARCH::datagen>(board, SearchParams(), ctx);
|
||||
|
||||
if (!results.bestMove) break;
|
||||
|
||||
+28
-1
@@ -92,6 +92,31 @@ 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) {
|
||||
int reduction = 0;
|
||||
|
||||
@@ -147,6 +172,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc
|
||||
Board copy = board;
|
||||
int isLegal = copy.MakeMove(board.moveList[i]);
|
||||
if (!isLegal) continue;
|
||||
ctx.positionHistory[copy.positionIndex] = copy.hashKey;
|
||||
ctx.nodes++;
|
||||
int score = -Quiescence<mode>(copy, -beta, -alpha, ply + 1, ctx).score;
|
||||
|
||||
@@ -191,7 +217,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
|
||||
}
|
||||
|
||||
ctx.pvLine.SetLength(ply);
|
||||
if (ply && (board.IsDraw())) return 0;
|
||||
if (ply && (IsDraw(board, ctx))) return 0;
|
||||
|
||||
|
||||
// if NOT PV node then we try to hit the TTable
|
||||
@@ -261,6 +287,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
|
||||
bool isLegal = copy.MakeMove(currMove);
|
||||
|
||||
if (!isLegal) continue;
|
||||
ctx.positionHistory[copy.positionIndex] = copy.hashKey;
|
||||
ctx.nodes++;
|
||||
|
||||
int reductions = GetReductions(board, currMove, depth, moveSeen, ply);
|
||||
|
||||
+3
-1
@@ -113,6 +113,7 @@ public:
|
||||
History history;
|
||||
|
||||
std::array<std::array<int, MAX_PLY>, 2> killerMoves{};
|
||||
std::array<U64, 1000> positionHistory;
|
||||
|
||||
Stopwatch sw;
|
||||
|
||||
@@ -121,6 +122,7 @@ public:
|
||||
history.Clear();
|
||||
sw.Restart();
|
||||
killerMoves = {};
|
||||
positionHistory = {};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -130,7 +132,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
|
||||
template <searchMode mode>
|
||||
SearchResults SearchPosition(Board &board, SearchParams params, SearchContext& ctx);
|
||||
|
||||
bool IsDraw(Board &board);
|
||||
bool IsDraw(Board &board, SearchContext& ctx);
|
||||
|
||||
constexpr int moveScoreTable[6][6] = {
|
||||
105, 205, 305, 405, 505, 605,
|
||||
|
||||
Reference in new issue
Block a user