Skip to content

Commit

Permalink
Late Move Pruning without "Check" requirement (#111)
Browse files Browse the repository at this point in the history
Bench: 10603549

ELO | 1.82 +- 1.98 (95%)
SPRT | 8.0+0.08s Threads=1 Hash=16MB
LLR | 9.83 (-2.94, 2.94) [-4.00, 1.00]
Games | N: 53436 W: 12292 L: 12012 D: 29132

http://167.114.125.235:8080/test/1331/
  • Loading branch information
jhonnold committed May 23, 2021
1 parent 37620a9 commit 48546fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
9 changes: 4 additions & 5 deletions src/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void AddHistoryHeuristic(SearchData* data, Move move, int stm, int inc) {
*e += 64 * inc - *e * abs(inc) / 1024;
}

void UpdateHistories(SearchData* data, Move bestMove, int depth, int stm, MoveList* moves, int c) {
void UpdateHistories(SearchData* data, Move bestMove, int depth, int stm, MoveList* quiets) {
int inc = min(depth * depth, 576);

if (!Tactical(bestMove)) {
Expand All @@ -44,8 +44,7 @@ void UpdateHistories(SearchData* data, Move bestMove, int depth, int stm, MoveLi
AddHistoryHeuristic(data, bestMove, stm, inc);
}

for (int i = 0; i < c; i++) {
if (!Tactical(moves->moves[i]))
AddHistoryHeuristic(data, moves->moves[i], stm, -inc);
}
for (int i = 0; i < quiets->count; i++)
if (quiets->moves[i] != bestMove)
AddHistoryHeuristic(data, quiets->moves[i], stm, -inc);
}
2 changes: 1 addition & 1 deletion src/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
void AddKillerMove(SearchData* data, Move move);
void AddCounterMove(SearchData* data, Move move, Move parent);
void AddHistoryHeuristic(SearchData* data, Move move, int stm, int inc);
void UpdateHistories(SearchData* data, Move bestMove, int depth, int stm, MoveList* moves, int c);
void UpdateHistories(SearchData* data, Move bestMove, int depth, int stm, MoveList* quiets);

#endif
49 changes: 28 additions & 21 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,12 @@ int Negamax(int alpha, int beta, int depth, ThreadData* thread, PV* pv) {
MoveList moveList;
GenerateAllMoves(&moveList, board, data);

int numMoves = 0;
MoveList quiets;
quiets.count = 0;

// TODO: totalMoves will just become standard moves with a proper phased generation
// nonPrunedMoves are moves that aren't skipped by LMP but get pruned by SEE
int totalMoves = 0, nonPrunedMoves = 0;
for (int i = 0; i < moveList.count; i++) {
ChooseTopMove(&moveList, i);
Move move = moveList.moves[i];
Expand All @@ -354,30 +359,32 @@ int Negamax(int alpha, int beta, int depth, ThreadData* thread, PV* pv) {
if (skipMove == move)
continue;

int doesCheck = DoesMoveCheck(move, board);
int tactical = MovePromo(move) || MoveCapture(move);

if (!isPV && bestScore > -MATE_BOUND) {
// late move pruning at low depth if it's quiet and we've looked at ALOT
if (depth <= 8 && !tactical && !doesCheck && numMoves >= LMP[improving][depth])
continue;
if (bestScore > -MATE_BOUND && depth <= 8 && !tactical && totalMoves > LMP[improving][depth])
continue;

// Static evaluation pruning, this applies for both quiet and tactical moves
// quiet moves use a quadratic scale upwards
if (SEE(board, move) < STATIC_PRUNE[tactical][depth])
continue;
}
totalMoves++;

// Static evaluation pruning, this applies for both quiet and tactical moves
// quiet moves use a quadratic scale upwards
if (bestScore > -MATE_BOUND && SEE(board, move) < STATIC_PRUNE[tactical][depth])
continue;

nonPrunedMoves++;

numMoves++;
if (isRoot && !thread->idx && GetTimeMS() - 2500 >= params->startTime)
printf("info depth %d currmove %s currmovenumber %d\n", depth, MoveToStr(move), numMoves);
printf("info depth %d currmove %s currmovenumber %d\n", depth, MoveToStr(move), nonPrunedMoves);

if (!tactical)
quiets.moves[quiets.count++] = move;

// singular extension
// if one move is better than all the rest, then we consider this singular
// and look at it more (extend). Singular is determined by checking all other
// moves at a shallow depth on a nullwindow that is somewhere below the tt evaluation
// implemented using "skip move" recursion like in SF (allows for reductions when doing singular search)
int extension = doesCheck;
int extension = 0;
if (depth >= 8 && !skipMove && !isRoot && move == TTMove(ttValue) && TTDepth(ttValue) >= depth - 3 &&
abs(TTScore(ttValue, data->ply)) < MATE_BOUND && TTFlag(ttValue) == TT_LOWER) {
int sBeta = max(TTScore(ttValue, data->ply) - depth * 2, -CHECKMATE);
Expand Down Expand Up @@ -405,16 +412,16 @@ int Negamax(int alpha, int beta, int depth, ThreadData* thread, PV* pv) {
extension = 1;
}

// apply extensions
int newDepth = depth + extension;

data->moves[data->ply++] = move;
MakeMove(move, board);

// apply extensions
int newDepth = depth + max(extension, !!board->checkers);

// Late move reductions
int R = 1;
if (depth > 2 && numMoves > 1) {
R = LMR[min(depth, 63)][min(numMoves, 63)];
if (depth > 2 && nonPrunedMoves > 1) {
R = LMR[min(depth, 63)][min(nonPrunedMoves, 63)];

if (!tactical) {
// increase reduction on non-pv
Expand All @@ -441,7 +448,7 @@ int Negamax(int alpha, int beta, int depth, ThreadData* thread, PV* pv) {
}

// First move of a PV node
if (isPV && numMoves == 1) {
if (isPV && nonPrunedMoves == 1) {
score = -Negamax(-beta, -alpha, newDepth - 1, thread, &childPv);
} else {
// potentially reduced search
Expand Down Expand Up @@ -472,7 +479,7 @@ int Negamax(int alpha, int beta, int depth, ThreadData* thread, PV* pv) {

// we're failing high
if (alpha >= beta) {
UpdateHistories(data, move, depth, board->side, &moveList, i);
UpdateHistories(data, move, depth, board->side, &quiets);
break;
}
}
Expand Down

0 comments on commit 48546fb

Please sign in to comment.