Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix rare crash on HT collisions
Due to a race, or even a collision (single threaded), the he.eval can be wrong.
And so we cannot deduce that we are not in check by trusting this value. And, of
course, doing a null move in check is a disaster, the opponent will capture our
king, and the engine crashes soon after.

Hopefully Demolito is now ready for 176 threads in TCEC without crashes :)
  • Loading branch information
lucasart committed Dec 29, 2019
1 parent 513ae8b commit 0a9a0fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/position.c
Expand Up @@ -314,7 +314,9 @@ void pos_move(Position *pos, const Position *before, move_t m)

// Capture piece on to square (if any)
if (capture != NB_PIECE) {
assert(capture != KING);
pos->rule50 = 0;

// Use pos_color_on() instead of them, because we could be playing a KxR castling here
clear_square(pos, pos_color_on(pos, to), capture, to);

Expand Down
6 changes: 4 additions & 2 deletions src/search.c
Expand Up @@ -281,9 +281,11 @@ static int search(Worker *worker, const Position *pos, int ply, int depth, int a
}

// Null search
if (depth >= 2 && !pvNode
if (depth >= 2 && !pvNode && !pos->checkers
&& staticEval >= beta && pos->pieceMaterial[us].eg) {
assert(!pos->checkers);
// Note that staticEval >= beta should exclude the case where we are in check (eval() cannot be called in
// check and a value -MATE is assigned). But with HT races or even HT collisions in single threaded case,
// one cannot make any assumptions on HT data.
const int nextDepth = depth - (3 + depth / 4) - (refinedEval >= beta + 167);

pos_switch(&nextPos, pos);
Expand Down

0 comments on commit 0a9a0fd

Please sign in to comment.