Skip to content

Commit

Permalink
Bench: 18339698
Browse files Browse the repository at this point in the history
  • Loading branch information
TerjeKir committed Oct 19, 2023
1 parent 2efd0f4 commit 51f1442
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ INLINE void UpdateContHistories(Stack *ss, Move move, int bonus) {
INLINE void UpdateQuietHistory(Thread *thread, Stack *ss, Move bestMove, int bonus, Depth depth, Move quiets[], int qCount) {

// Update killers
if (ss->killers[0] != bestMove) {
if (!ss->inCheck && ss->killers[0] != bestMove) {
ss->killers[1] = ss->killers[0];
ss->killers[0] = bestMove;
}
Expand Down
4 changes: 2 additions & 2 deletions src/movepicker.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ void InitNormalMP(MovePicker *mp, Thread *thread, Stack *ss, Depth depth, Move t
mp->ttMove = ttMove;
mp->stage = ttMove ? TTMOVE : GEN_NOISY;
mp->depth = depth;
mp->kill1 = kill1;
mp->kill2 = kill2;
mp->kill1 = !ss->inCheck ? kill1 : NOMOVE;
mp->kill2 = !ss->inCheck ? kill2 : NOMOVE;
mp->bads = 0;
mp->threshold = 0;
mp->onlyNoisy = false;
Expand Down
26 changes: 13 additions & 13 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, const int beta) {
MovePicker mp;

const bool pvNode = alpha != beta - 1;
const bool inCheck = pos->checkers;
ss->inCheck = pos->checkers;

int eval = NOSCORE;
int futility = -INFINITE;
Expand Down Expand Up @@ -115,7 +115,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, const int beta) {
if (ss->ply >= MAX_PLY)
return eval;

if (inCheck) goto moveloop;
if (ss->inCheck) goto moveloop;

// If eval beats beta we assume some move will also beat it
if (eval >= beta)
Expand All @@ -130,7 +130,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, const int beta) {

moveloop:

if (!inCheck) InitNoisyMP(&mp, thread, ss, ttMove); else InitNormalMP(&mp, thread, ss, 0, ttMove, NOMOVE, NOMOVE);
if (!ss->inCheck) InitNoisyMP(&mp, thread, ss, ttMove); else InitNormalMP(&mp, thread, ss, 0, ttMove, NOMOVE, NOMOVE);

// Move loop
Move bestMove = NOMOVE;
Expand Down Expand Up @@ -159,7 +159,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, const int beta) {
}

search:
ss->continuation = &thread->continuation[inCheck][moveIsCapture(move)][piece(move)][toSq(move)];
ss->continuation = &thread->continuation[ss->inCheck][moveIsCapture(move)][piece(move)][toSq(move)];

// Recursively search the positions after making the moves, skipping illegal ones
if (!MakeMove(pos, move)) continue;
Expand All @@ -183,7 +183,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, const int beta) {
}

// Checkmate
if (inCheck && bestScore == -INFINITE)
if (ss->inCheck && bestScore == -INFINITE)
return -MATE + ss->ply;

StoreTTEntry(tte, key, bestMove, ScoreToTT(bestScore, ss->ply), eval, 0,
Expand Down Expand Up @@ -287,10 +287,10 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
}
}

const bool inCheck = pos->checkers;
ss->inCheck = pos->checkers;

// Do a static evaluation for pruning considerations
int eval = ss->eval = inCheck ? NOSCORE
int eval = ss->eval = ss->inCheck ? NOSCORE
: lastMoveNullMove ? -(ss-1)->eval + 2 * Tempo
: ttEval != NOSCORE ? ttEval
: EvalPosition(pos, thread->pawnCache);
Expand All @@ -301,7 +301,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
eval = ttScore;

// Improving if not in check, and current eval is higher than 2 plies ago
bool improving = !inCheck && eval > (ss-2)->eval;
bool improving = !ss->inCheck && eval > (ss-2)->eval;

// Internal iterative reduction based on Rebel's idea
if (pvNode && depth >= 4 && !ttMove)
Expand All @@ -311,7 +311,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 || history(-1).move == NOMOVE)
if (ss->inCheck || pvNode || !thread->doPruning || ss->excluded || abs(beta) >= TBWIN_IN_MAX || history(-1).move == NOMOVE)
goto move_loop;

// Reverse Futility Pruning
Expand Down Expand Up @@ -363,7 +363,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth

if (!MakeMove(pos, move)) continue;

ss->continuation = &thread->continuation[inCheck][moveIsCapture(move)][piece(move)][toSq(move)];
ss->continuation = &thread->continuation[ss->inCheck][moveIsCapture(move)][piece(move)][toSq(move)];

// See if a quiescence search beats the threshold
int score = -Quiescence(thread, ss+1, -probCutBeta, -probCutBeta+1);
Expand Down Expand Up @@ -471,13 +471,13 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
}

// Extend when in check
if (inCheck)
if (ss->inCheck)
extension = MAX(extension, 1);

skip_extensions:

ss->doubleExtensions = (ss-1)->doubleExtensions + (extension == 2);
ss->continuation = &thread->continuation[inCheck][moveIsCapture(move)][piece(move)][toSq(move)];
ss->continuation = &thread->continuation[ss->inCheck][moveIsCapture(move)][piece(move)][toSq(move)];

Depth newDepth = depth - 1 + extension;

Expand Down Expand Up @@ -570,7 +570,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
// Checkmate or stalemate
if (!moveCount)
bestScore = ss->excluded ? alpha
: inCheck ? -MATE + ss->ply
: ss->inCheck ? -MATE + ss->ply
: 0;

// Make sure score isn't above the max score given by TBs
Expand Down
1 change: 1 addition & 0 deletions src/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct {
Depth ply;
Move excluded;
Move killers[2];
bool inCheck;
PV pv;
} Stack;

Expand Down

0 comments on commit 51f1442

Please sign in to comment.