Skip to content

Commit

Permalink
smaller TEntry and different replacement strategy (#98)
Browse files Browse the repository at this point in the history
Bench: 621764
  • Loading branch information
Disservin authored Jun 29, 2022
1 parent 5e0ecbf commit 08d7bc9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ int Search::absearch(int depth, int alpha, int beta, int ply, Stack *ss) {
UpdateHH(bestMove, depth, quietMoves);

// Store position in TT
if (!exit_early()) store_entry(depth, best, oldAlpha, beta, board.hashKey, startAge, bestMove.get());
if (!exit_early()) store_entry(depth, best, oldAlpha, beta, board.hashKey, bestMove.get());
return best;
}

Expand Down Expand Up @@ -413,7 +413,6 @@ int Search::iterative_deepening(int search_depth, uint64_t maxN, Time time) {
maxNodes = maxN;

// TT starting age of this searches entries
startAge = board.fullMoveNumber;

int result = 0;
Move prev_bestmove{};
Expand Down
3 changes: 1 addition & 2 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class Search {
// bestmove
Move bestMove{};

// startAge and seldepth
uint16_t startAge{};
//seldepth
uint8_t seldepth{};

// move ordering and time usage
Expand Down
28 changes: 11 additions & 17 deletions src/tt.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
#include "tt.h"

bool store_entry(int depth, int bestvalue,
void store_entry(int depth, int bestvalue,
int old_alpha, int beta, U64 key,
uint16_t startAge, uint16_t move) {
U64 index = key % TT_SIZE;
uint16_t move)
{
U64 index = key % TT_SIZE;
TEntry tte = TTable[index];
if (!(bestvalue >= 19000) && !(bestvalue <= -19000) &&
(tte.depth < depth || tte.age + 3 <= startAge)) {
tte.flag = EXACT;
// Upperbound
if (bestvalue <= old_alpha) {
tte.flag = UPPERBOUND;
}
// Lowerbound
else if (bestvalue >= beta) {
tte.flag = LOWERBOUND;
}

Flag b = bestvalue <= old_alpha ? UPPERBOUND : bestvalue >= beta ? LOWERBOUND : EXACT;

if (bestvalue < 19000 && bestvalue > -19000
&& (tte.key != key || b == EXACT || depth > (tte.depth * 2) / 3))
{
tte.depth = depth;
tte.score = bestvalue;
tte.age = startAge;
tte.key = key;
tte.move = move;
tte.flag = b;
TTable[index] = tte;
return true;
}
return false;
}

void probe_tt(TEntry &tte, bool &ttHit, U64 key, int depth)
Expand Down
5 changes: 2 additions & 3 deletions src/tt.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ struct TEntry {
U64 key;
int score;
uint16_t move;
uint16_t age;
uint8_t depth;
Flag flag;
}__attribute__((packed));

extern TEntry* TTable;
extern U64 TT_SIZE;

bool store_entry(int depth, int bestvalue,
void store_entry(int depth, int bestvalue,
int old_alpha, int beta, U64 key,
uint16_t startAge, uint16_t move);
uint16_t move);

void probe_tt(TEntry &tte, bool &ttHit, U64 key, int depth);

0 comments on commit 08d7bc9

Please sign in to comment.