Skip to content

Commit

Permalink
SPSA tune search and history (#768)
Browse files Browse the repository at this point in the history
STC 25k vs master
Elo   | 6.98 +- 3.85 (95%)
SPRT  | 10.0+0.10s Threads=1 Hash=32MB
LLR   | 2.98 (-2.94, 2.94) [0.00, 3.00]
Games | N: 12740 W: 3796 L: 3540 D: 5404
Penta | [249, 1440, 2771, 1626, 284]
http://chess.grantnet.us/test/38736/

LTC 5k vs master
Elo   | 4.27 +- 2.70 (95%)
SPRT  | 60.0+0.60s Threads=1 Hash=128MB
LLR   | 2.96 (-2.94, 2.94) [0.00, 3.00]
Games | N: 18734 W: 5036 L: 4806 D: 8892
Penta | [120, 2150, 4618, 2338, 141]
http://chess.grantnet.us/test/38704/

LTC 15k vs 5k
Elo   | 5.53 +- 3.18 (95%)
SPRT  | 60.0+0.60s Threads=1 Hash=128MB
LLR   | 2.96 (-2.94, 2.94) [0.00, 3.00]
Games | N: 13938 W: 3702 L: 3480 D: 6756
Penta | [92, 1621, 3338, 1809, 109]
http://chess.grantnet.us/test/38720/

LTC 25k vs 15k
Elo   | 1.50 +- 1.21 (95%)
SPRT  | 60.0+0.60s Threads=1 Hash=128MB
LLR   | 2.96 (-2.94, 2.94) [0.00, 3.00]
Games | N: 95908 W: 25228 L: 24813 D: 45867
Penta | [690, 11447, 23290, 11812, 715]
http://chess.grantnet.us/test/38731/

Bench: 26649770
  • Loading branch information
TerjeKir authored Jan 29, 2025
1 parent 8048bb9 commit 693b322
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
44 changes: 22 additions & 22 deletions src/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
#define ContCorrEntry(offset) (&(*(ss-offset)->contCorr)[piece((ss-1)->move)][toSq((ss-1)->move)])
#define NonPawnCorrEntry(color) (&thread->nonPawnCorrHistory[color][thread->pos.stm][NonPawnCorrIndex(&thread->pos, color)])

#define QuietHistoryUpdate(move, bonus) (HistoryBonus(QuietEntry(move), bonus, 5280))
#define PawnHistoryUpdate(move, bonus) (HistoryBonus(PawnEntry(move), bonus, 9275))
#define NoisyHistoryUpdate(move, bonus) (HistoryBonus(NoisyEntry(move), bonus, 16000))
#define ContHistoryUpdate(offset, move, bonus) (HistoryBonus(ContEntry(offset, move), bonus, 21250))
#define PawnCorrHistoryUpdate(bonus) (HistoryBonus(PawnCorrEntry(), bonus, 1662))
#define MinorCorrHistoryUpdate(bonus) (HistoryBonus(MinorCorrEntry(), bonus, 1024))
#define MajorCorrHistoryUpdate(bonus) (HistoryBonus(MajorCorrEntry(), bonus, 1024))
#define ContCorrHistoryUpdate(offset, bonus) (HistoryBonus(ContCorrEntry(offset), bonus, 1220))
#define NonPawnCorrHistoryUpdate(bonus, color) (HistoryBonus(NonPawnCorrEntry(color), bonus, 1024))
#define QuietHistoryUpdate(move, bonus) (HistoryBonus(QuietEntry(move), bonus, 4373))
#define PawnHistoryUpdate(move, bonus) (HistoryBonus(PawnEntry(move), bonus, 8663))
#define NoisyHistoryUpdate(move, bonus) (HistoryBonus(NoisyEntry(move), bonus, 14387))
#define ContHistoryUpdate(offset, move, bonus) (HistoryBonus(ContEntry(offset, move), bonus, 16384))
#define PawnCorrHistoryUpdate(bonus) (HistoryBonus(PawnCorrEntry(), bonus, 1651))
#define MinorCorrHistoryUpdate(bonus) (HistoryBonus(MinorCorrEntry(), bonus, 1142))
#define MajorCorrHistoryUpdate(bonus) (HistoryBonus(MajorCorrEntry(), bonus, 1222))
#define ContCorrHistoryUpdate(offset, bonus) (HistoryBonus(ContCorrEntry(offset), bonus, 1514))
#define NonPawnCorrHistoryUpdate(bonus, color) (HistoryBonus(NonPawnCorrEntry(color), bonus, 1063))


INLINE int PawnStructure(const Position *pos) { return pos->pawnKey & (PAWN_HISTORY_SIZE - 1); }
Expand All @@ -61,15 +61,15 @@ INLINE void HistoryBonus(int16_t *entry, int bonus, int div) {
}

INLINE int Bonus(Depth depth) {
return MIN(2410, 268 * depth - 310);
return MIN(2418, 251 * depth - 267);
}

INLINE int Malus(Depth depth) {
return -MIN(834, 531 * depth - 148);
return -MIN(693, 532 * depth - 163);
}

INLINE int CorrectionBonus(int score, int eval, Depth depth) {
return CLAMP((score - eval) * depth / 4, -212, 254);
return CLAMP((score - eval) * depth / 4, -172, 289);
}

INLINE void UpdateContHistories(Stack *ss, Move move, int bonus) {
Expand Down Expand Up @@ -153,16 +153,16 @@ INLINE int GetHistory(const Thread *thread, Stack *ss, Move move) {
}

INLINE int GetCorrectionHistory(const Thread *thread, const Stack *ss) {
int c = 6554 * *PawnCorrEntry()
+ 6800 * *MinorCorrEntry()
+ 3700 * *MajorCorrEntry()
+ 7000 * (*NonPawnCorrEntry(WHITE) + *NonPawnCorrEntry(BLACK))
+ 3121 * *ContCorrEntry(2)
+ 2979 * *ContCorrEntry(3)
+ 2849 * *ContCorrEntry(4)
+ 3121 * *ContCorrEntry(5)
+ 2789 * *ContCorrEntry(6)
+ 2979 * *ContCorrEntry(7);
int c = 5868 * *PawnCorrEntry()
+ 7217 * *MinorCorrEntry()
+ 4416 * *MajorCorrEntry()
+ 7025 * (*NonPawnCorrEntry(WHITE) + *NonPawnCorrEntry(BLACK))
+ 4060 * *ContCorrEntry(2)
+ 3235 * *ContCorrEntry(3)
+ 2626 * *ContCorrEntry(4)
+ 3841 * *ContCorrEntry(5)
+ 3379 * *ContCorrEntry(6)
+ 2901 * *ContCorrEntry(7);

return c / 131072;
}
6 changes: 3 additions & 3 deletions src/movepicker.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void ScoreMoves(MovePicker *mp, const int stage) {
: GetCaptureHistory(thread, move) + PieceValue[MG][capturing(move)];
}

SortMoves(list, -1000 * mp->depth);
SortMoves(list, -750 * mp->depth);
}

// Returns the next move to try in a position
Expand All @@ -96,8 +96,8 @@ Move NextMove(MovePicker *mp) {
case NOISY_GOOD:
// Save seemingly bad noisy moves for later
while ((move = PickNextMove(mp)))
if ( mp->list.moves[mp->list.next-1].score > 11300
|| (mp->list.moves[mp->list.next-1].score > -11100 && SEE(pos, move, mp->threshold)))
if ( mp->list.moves[mp->list.next-1].score > 11046
|| (mp->list.moves[mp->list.next-1].score > - 9543 && SEE(pos, move, mp->threshold)))
return move;
else
mp->list.moves[mp->bads++].move = move;
Expand Down
28 changes: 14 additions & 14 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ static int Reductions[2][32][32];
CONSTR(1) InitReductions() {
for (int depth = 1; depth < 32; ++depth)
for (int moves = 1; moves < 32; ++moves)
Reductions[0][depth][moves] = 0.48 + log(depth) * log(moves) / 3.43, // capture
Reductions[1][depth][moves] = 1.92 + log(depth) * log(moves) / 2.46; // quiet
Reductions[0][depth][moves] = 0.38 + log(depth) * log(moves) / 3.76, // capture
Reductions[1][depth][moves] = 2.01 + log(depth) * log(moves) / 2.32; // quiet
}

// Checks whether a move was already searched in multi-pv mode
Expand Down Expand Up @@ -163,7 +163,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, int beta) {
if (eval > alpha)
alpha = eval;

futility = eval + 132;
futility = eval + 165;
bestScore = eval;

moveloop:
Expand Down Expand Up @@ -367,18 +367,18 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
// Reverse Futility Pruning
if ( depth < 7
&& eval >= beta
&& eval - 76 * (depth - improving) - (ss-1)->histScore / 119 >= beta
&& (!ttMove || GetHistory(thread, ss, ttMove) > 7600))
&& eval - 77 * (depth - improving) - (ss-1)->histScore / 131 >= beta
&& (!ttMove || GetHistory(thread, ss, ttMove) > 6450))
return eval;

// Null Move Pruning
if ( eval >= beta
&& eval >= ss->staticEval
&& ss->staticEval >= beta + 158 - 19 * depth
&& (ss-1)->histScore < 26300
&& ss->staticEval >= beta + 138 - 13 * depth
&& (ss-1)->histScore < 28500
&& pos->nonPawnCount[sideToMove] > (depth > 8)) {

Depth reduction = 4 + depth / 4 + MIN(3, (eval - beta) / 224);
Depth reduction = 4 + depth / 4 + MIN(3, (eval - beta) / 227);

ss->move = NOMOVE;
ss->continuation = &thread->continuation[0][0][EMPTY][0];
Expand Down Expand Up @@ -463,19 +463,19 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
&& thread->doPruning
&& !isLoss(bestScore)) {

int R = Reductions[quiet][MIN(31, depth)][MIN(31, moveCount)] - ss->histScore / 9050;
int R = Reductions[quiet][MIN(31, depth)][MIN(31, moveCount)] - ss->histScore / 9164;
Depth lmrDepth = depth - 1 - R;

// Quiet late move pruning
if (moveCount > (improving ? 1 + depth * depth : depth * depth / 2))
if (moveCount > (improving ? 2 + depth * depth : depth * depth / 2))
mp.onlyNoisy = true;

// History pruning
if (lmrDepth < 3 && ss->histScore < -1024 * depth)
continue;

// SEE pruning
if (lmrDepth < 7 && !SEE(pos, move, -63 * depth))
if (lmrDepth < 7 && !SEE(pos, move, -73 * depth))
continue;
}

Expand Down Expand Up @@ -536,7 +536,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
// Base reduction
int r = Reductions[quiet][MIN(31, depth)][MIN(31, moveCount)];
// Adjust reduction by move history
r -= ss->histScore / 10135;
r -= ss->histScore / 8870;
// Reduce less in pv nodes
r -= pvNode;
// Reduce less when improving
Expand All @@ -555,7 +555,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth

// Re-search with the same window at full depth if the reduced search failed high
if (score > alpha && lmrDepth < newDepth) {
bool deeper = score > bestScore + 1 + 7 * (newDepth - lmrDepth);
bool deeper = score > bestScore + 1 + 6 * (newDepth - lmrDepth);

newDepth += deeper;

Expand Down Expand Up @@ -750,7 +750,7 @@ static void *IterativeDeepening(void *voidThread) {
Limits.optimalUsage = MIN(500, Limits.optimalUsage);

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

// If an iteration finishes after optimal time usage, stop the search
if ( Limits.timelimit
Expand Down

0 comments on commit 693b322

Please sign in to comment.