Skip to content

Commit

Permalink
Bench: 23851500
Browse files Browse the repository at this point in the history
  • Loading branch information
TerjeKir committed Dec 21, 2024
1 parent 352c5f5 commit 2259da0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
18 changes: 9 additions & 9 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, int beta) {
eval = CorrectEval(thread, ss, eval, pos->rule50);

// Use ttScore as eval if it is more informative
if (abs(ttScore) < TBWIN_IN_MAX && TTScoreIsMoreInformative(ttBound, ttScore, eval))
if (!isTerminal(ttScore) && TTScoreIsMoreInformative(ttBound, ttScore, eval))
eval = ttScore;

// If eval beats beta we assume some move will also beat it
Expand All @@ -176,7 +176,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, int beta) {
while ((move = NextMove(&mp))) {

// Avoid pruning until at least one move avoids a terminal loss score
if (bestScore <= -TBWIN_IN_MAX) goto search;
if (isLoss(bestScore)) goto search;

// Only try moves the movepicker deems good
if (mp.stage > NOISY_GOOD) break;
Expand Down Expand Up @@ -344,7 +344,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
ss->staticEval = eval = CorrectEval(thread, ss, eval, pos->rule50);

// Use ttScore as eval if it is more informative
if (abs(ttScore) < TBWIN_IN_MAX && TTScoreIsMoreInformative(ttBound, ttScore, eval))
if (!isTerminal(ttScore) && TTScoreIsMoreInformative(ttBound, ttScore, eval))
eval = ttScore;

// Improving if not in check, and current eval is higher than 2 plies ago
Expand All @@ -358,7 +358,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
depth--;

// Skip pruning in check, pv nodes, early iterations, when proving singularity, looking for terminal scores, or after a null move
if (inCheck || pvNode || !thread->doPruning || ss->excluded || abs(beta) >= TBWIN_IN_MAX || (ss-1)->move == NOMOVE)
if (inCheck || pvNode || !thread->doPruning || ss->excluded || isTerminal(beta) || (ss-1)->move == NOMOVE)
goto move_loop;

// Reverse Futility Pruning
Expand Down Expand Up @@ -388,7 +388,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
// Cutoff
if (score >= beta)
// Don't return unproven terminal win scores
return score >= TBWIN_IN_MAX ? beta : score;
return isWin(score) ? beta : score;
}

int probCutBeta = beta + 200;
Expand Down Expand Up @@ -421,7 +421,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth

// Cut if the reduced depth search beats the threshold, terminal scores are exact
if (score >= probCutBeta)
return score < TBWIN_IN_MAX ? score - 160 : score;
return isWin(score) ? score : score - 160;
}
}

Expand Down Expand Up @@ -454,7 +454,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
// Misc pruning
if ( !root
&& thread->doPruning
&& bestScore > -TBWIN_IN_MAX) {
&& !isLoss(bestScore)) {

int R = Reductions[quiet][MIN(31, depth)][MIN(31, moveCount)] - ss->histScore / 9050;
Depth lmrDepth = depth - 1 - R;
Expand Down Expand Up @@ -490,7 +490,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
&& !ss->excluded
&& ttDepth > depth - 3
&& ttBound != BOUND_UPPER
&& abs(ttScore) < TBWIN_IN_MAX / 4) {
&& !isTerminal(ttScore)) {

// ttMove has been made to check legality
TakeMove(pos);
Expand Down Expand Up @@ -698,7 +698,7 @@ static void AspirationWindow(Thread *thread, Stack *ss) {
// Failed high, relax upper bound and search again
} else if (score >= beta) {
beta = MIN(beta + delta, INFINITE);
depth = MAX(1, depth - (abs(score) < TBWIN_IN_MAX));
depth = MAX(1, depth - !isTerminal(score));

// Score inside the window
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/transposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ INLINE bool EntryEmpty(TTEntry *entry) { return Bound(entry) == BOUND_NONE; }

// Store terminal scores as distance from the current position to mate/TB
INLINE int ScoreToTT (const int score, const uint8_t ply) {
return score >= TBWIN_IN_MAX ? score + ply
: score <= -TBWIN_IN_MAX ? score - ply
: score;
return isWin(score) ? score + ply
: isLoss(score) ? score - ply
: score;
}

// Add the distance from root to terminal scores get the total distance to mate/TB
INLINE int ScoreFromTT (const int score, const uint8_t ply) {
return score >= TBWIN_IN_MAX ? score - ply
: score <= -TBWIN_IN_MAX ? score + ply
: score;
return isWin(score) ? score - ply
: isLoss(score) ? score + ply
: score;
}

// Checks whether the TT score is more informative than score
Expand Down
4 changes: 4 additions & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#define pieceTypeOn(sq) (PieceTypeOf(pieceOn(sq)))
#define kingSq(color) (Lsb(colorPieceBB(color, KING)))

#define isLoss(score) (score <= -TBWIN_IN_MAX)
#define isWin(score) (score >= TBWIN_IN_MAX)
#define isMate(score) (abs(score) >= MATE_IN_MAX)
#define isTerminal(score) (isWin(score) || isLoss(score))

typedef uint64_t Bitboard;
typedef uint64_t Key;
Expand Down
10 changes: 5 additions & 5 deletions src/uci.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,18 @@ void PrintThinking(const Thread *thread, int alpha, int beta) {
if (pv->length == 0) break;

// Determine whether we have a centipawn or mate score
char *type = abs(score) >= MATE_IN_MAX ? "mate" : "cp";
char *type = isMate(score) ? "mate" : "cp";

// Determine if score is a lower bound, upper bound or exact
char *bound = score >= beta ? " lowerbound"
: score <= alpha ? " upperbound"
: "";

// Translate internal score into printed score
score = abs(score) >= MATE_IN_MAX ? MateScore(score)
: abs(score) <= 8
&& pv->length <= 2 ? 0
: score;
score = isMate(score) ? MateScore(score)
: abs(score) <= 8
&& pv->length <= 2 ? 0
: score;

// Basic info
printf("info depth %d seldepth %d multipv %d score %s %d%s time %" PRId64
Expand Down

0 comments on commit 2259da0

Please sign in to comment.