Skip to content

Commit

Permalink
Adjust time spent based on how much of the search effort goes into th…
Browse files Browse the repository at this point in the history
…e top move (#752)

Elo   | 11.37 +- 4.93 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=32MB
LLR   | 3.04 (-2.94, 2.94) [0.00, 3.00]
Games | N: 7216 W: 2084 L: 1848 D: 3284
Penta | [102, 790, 1642, 918, 156]
http://chess.grantnet.us/test/38596/

Elo   | 11.76 +- 4.85 (95%)
SPRT  | 40.0+0.40s Threads=1 Hash=128MB
LLR   | 2.97 (-2.94, 2.94) [0.00, 3.00]
Games | N: 6178 W: 1638 L: 1429 D: 3111
Penta | [54, 657, 1451, 880, 47]
http://chess.grantnet.us/test/38598/

Bench: 26587524
  • Loading branch information
TerjeKir authored Dec 18, 2024
1 parent 13f9bd8 commit 1401211
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth

bool quiet = moveIsQuiet(move);

uint64_t startingNodes = pos->nodes;

ss->histScore = GetHistory(thread, ss, move);

// Misc pruning
Expand Down Expand Up @@ -579,6 +581,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth

if (moveCount == 1 || score > alpha) {
rm->score = score;
rm->nodes += pos->nodes - startingNodes;
rm->pv.length = 1 + (ss+1)->pv.length;
rm->pv.line[0] = move;
memcpy(rm->pv.line+1, (ss+1)->pv.line, sizeof(Move) * (ss+1)->pv.length);
Expand Down Expand Up @@ -736,10 +739,13 @@ static void *IterativeDeepening(void *voidThread) {
if (thread->rootMoveCount == 1 && Limits.timelimit && !Limits.movetime)
Limits.optimalUsage = MIN(500, Limits.optimalUsage);

double nodeRatio = 1.0 - (double)thread->rootMoves[0].nodes / (MAX(1, pos->nodes));
double timeRatio = 0.5 + 2.5 * nodeRatio;

// If an iteration finishes after optimal time usage, stop the search
if ( Limits.timelimit
&& !thread->uncertain
&& TimeSince(Limits.start) > Limits.optimalUsage)
&& TimeSince(Limits.start) > Limits.optimalUsage * timeRatio)
break;

// Clear key history for seldepth calculation
Expand Down
1 change: 1 addition & 0 deletions src/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef struct {
typedef struct RootMove {
Move move;
int score;
uint64_t nodes;
PV pv;
} RootMove;

Expand Down

0 comments on commit 1401211

Please sign in to comment.