Skip to content

Commit

Permalink
Bench: 24879040
Browse files Browse the repository at this point in the history
  • Loading branch information
TerjeKir committed Jan 3, 2025
1 parent 54e8064 commit a26356d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ Key KeyAfter(const Position *pos, const Move move) {
if (capt)
key ^= PieceKeys[capt][to];

return key ^ PieceKeys[piece][from] ^ PieceKeys[piece][to];
key ^= PieceKeys[piece][from] ^ PieceKeys[piece][to];

return (capt || PieceTypeOf(piece) == PAWN) ? key : Mr50KeyAfterMove(key, pos->rule50);
}

// Add a piece piece to a square
Expand Down
4 changes: 4 additions & 0 deletions src/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ INLINE bool ValidPiece(const Piece piece) { return (wP <= piece && piece <= wK)
INLINE bool ValidCapture(const Piece capt) { return (wP <= capt && capt <= wQ) || (bP <= capt && capt <= bQ); }
INLINE bool ValidPromotion(const Piece promo) { return (wN <= promo && promo <= wQ) || (bN <= promo && promo <= bQ); }

INLINE Key MakeKey(uint64_t seed) { return seed * 6364136223846793005ULL + 1442695040888963407ULL; }
INLINE Key Mr50Key(const Position *pos) { return pos->rule50 < 14 ? pos->key : pos->key ^ MakeKey((pos->rule50 - 14) / 8); }
INLINE Key Mr50KeyAfterMove(Key key, int rule50) { return rule50 < 13 ? key : key ^ MakeKey((rule50 - 13) / 8); }

INLINE Color ColorOf(Piece piece) { return piece >> 3;}
INLINE PieceType PieceTypeOf(Piece piece) { return piece & 7; }
INLINE Piece MakePiece(Color color, PieceType pt) { return (color << 3) + pt; }
Expand Down
12 changes: 7 additions & 5 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, int beta) {

// Probe transposition table
bool ttHit;
TTEntry *tte = ProbeTT(pos->key, &ttHit);
Key key = Mr50Key(pos);
TTEntry *tte = ProbeTT(key, &ttHit);

Move ttMove = ttHit ? tte->move : NOMOVE;
int ttScore = ttHit ? ScoreFromTT(tte->score, ss->ply) : NOSCORE;
Expand Down Expand Up @@ -230,7 +231,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, int beta) {
if (inCheck && bestScore == -INFINITE)
return matedIn(ss->ply);

StoreTTEntry(tte, pos->key, bestMove, ScoreToTT(bestScore, ss->ply), unadjustedEval, 0,
StoreTTEntry(tte, key, bestMove, ScoreToTT(bestScore, ss->ply), unadjustedEval, 0,
bestScore >= beta ? BOUND_LOWER : BOUND_UPPER);

return bestScore;
Expand Down Expand Up @@ -287,7 +288,8 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth

// Probe transposition table
bool ttHit;
TTEntry *tte = ProbeTT(pos->key, &ttHit);
Key key = Mr50Key(pos);
TTEntry *tte = ProbeTT(key, &ttHit);

Move ttMove = ttHit ? tte->move : NOMOVE;
int ttScore = ttHit ? ScoreFromTT(tte->score, ss->ply) : NOSCORE;
Expand Down Expand Up @@ -321,7 +323,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth

// Draw scores are exact, while wins are lower bounds and losses upper bounds (mate scores are better/worse)
if (bound == BOUND_EXACT || (bound == BOUND_LOWER ? tbScore >= beta : tbScore <= alpha)) {
StoreTTEntry(tte, pos->key, NOMOVE, ScoreToTT(tbScore, ss->ply), NOSCORE, MAX_PLY, bound);
StoreTTEntry(tte, key, NOMOVE, ScoreToTT(tbScore, ss->ply), NOSCORE, MAX_PLY, bound);
return tbScore;
}

Expand Down Expand Up @@ -635,7 +637,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth

// Store in TT
if (!ss->excluded && (!root || !thread->multiPV))
StoreTTEntry(tte, pos->key, bestMove, ScoreToTT(bestScore, ss->ply), unadjustedEval, depth,
StoreTTEntry(tte, key, bestMove, ScoreToTT(bestScore, ss->ply), unadjustedEval, depth,
bestScore >= beta ? BOUND_LOWER
: pvNode && bestMove ? BOUND_EXACT
: BOUND_UPPER);
Expand Down

0 comments on commit a26356d

Please sign in to comment.