Skip to content

Commit

Permalink
Add pawn structure history (#705)
Browse files Browse the repository at this point in the history
Elo   | 4.30 +- 3.35 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=32MB
LLR   | 2.97 (-2.94, 2.94) [0.00, 3.00]
Games | N: 21672 W: 5826 L: 5558 D: 10288
Penta | [339, 2546, 4823, 2764, 364]
http://chess.grantnet.us/test/34696/

Elo   | 1.89 +- 1.92 (95%)
SPRT  | 40.0+0.40s Threads=1 Hash=128MB
LLR   | 2.95 (-2.94, 2.94) [0.00, 3.00]
Games | N: 59734 W: 14432 L: 14107 D: 31195
Penta | [378, 7041, 14763, 7248, 437]
http://chess.grantnet.us/test/34702/

Bench: 21514164
  • Loading branch information
TerjeKir authored Dec 10, 2023
1 parent 607b503 commit 20c95ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@


#define QuietEntry(move) (&thread->history[thread->pos.stm][fromSq(move)][toSq(move)])
#define PawnEntry(move) (&thread->pawnHistory[PawnStructure(&thread->pos)][piece(move)][toSq(move)])
#define NoisyEntry(move) (&thread->captureHistory[piece(move)][toSq(move)][PieceTypeOf(capturing(move))])
#define ContEntry(offset, move) (&(*(ss-offset)->continuation)[piece(move)][toSq(move)])

#define QuietHistoryUpdate(move, bonus) (HistoryBonus(QuietEntry(move), bonus, 7180))
#define PawnHistoryUpdate(move, bonus) (HistoryBonus(PawnEntry(move), bonus, 8192))
#define NoisyHistoryUpdate(move, bonus) (HistoryBonus(NoisyEntry(move), bonus, 16384))
#define ContHistoryUpdate(offset, move, bonus) (HistoryBonus(ContEntry(offset, move), bonus, 28650))

Expand Down Expand Up @@ -68,12 +70,14 @@ INLINE void UpdateQuietHistory(Thread *thread, Stack *ss, Move bestMove, Depth d
// Bonus to the move that caused the beta cutoff
if (depth > 2) {
QuietHistoryUpdate(bestMove, bonus);
PawnHistoryUpdate(bestMove, bonus);
UpdateContHistories(ss, bestMove, bonus);
}

// Penalize quiet moves that failed to produce a cut
for (Move *move = quiets; move < quiets + qCount; ++move) {
QuietHistoryUpdate(*move, malus);
PawnHistoryUpdate(*move, malus);
UpdateContHistories(ss, *move, malus);
}
}
Expand All @@ -99,6 +103,7 @@ INLINE void UpdateHistory(Thread *thread, Stack *ss, Move bestMove, Depth depth,

INLINE int GetQuietHistory(const Thread *thread, Stack *ss, Move move) {
return *QuietEntry(move)
+ *PawnEntry(move)
+ *ContEntry(1, move)
+ *ContEntry(2, move)
+ *ContEntry(4, move);
Expand Down
1 change: 1 addition & 0 deletions src/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void ResetThreads() {
for (int i = 0; i < threads->count; ++i)
memset(threads[i].pawnCache, 0, sizeof(PawnCache)),
memset(threads[i].history, 0, sizeof(threads[i].history)),
memset(threads[i].pawnHistory, 0, sizeof(threads[i].pawnHistory)),
memset(threads[i].captureHistory, 0, sizeof(threads[i].captureHistory)),
memset(threads[i].continuation, 0, sizeof(threads[i].continuation));
}
Expand Down
6 changes: 6 additions & 0 deletions src/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@

#define SS_OFFSET 10
#define MULTI_PV_MAX 64
#define PAWN_HISTORY_SIZE 512

INLINE int PawnStructure(const Position *pos) {
return pos->pawnKey & (PAWN_HISTORY_SIZE - 1);
}

typedef int16_t ButterflyHistory[COLOR_NB][64][64];
typedef int16_t PawnHistory[PAWN_HISTORY_SIZE][PIECE_NB][64];
typedef int16_t CaptureToHistory[PIECE_NB][64][TYPE_NB];
typedef int16_t PieceToHistory[PIECE_NB][64];
typedef PieceToHistory ContinuationHistory[PIECE_NB][64];
Expand Down Expand Up @@ -68,6 +73,7 @@ typedef struct Thread {
Position pos;
PawnCache pawnCache;
ButterflyHistory history;
PawnHistory pawnHistory;
CaptureToHistory captureHistory;
ContinuationHistory continuation[2][2];

Expand Down

0 comments on commit 20c95ce

Please sign in to comment.