rule50: Detect rule50 when searching

This commit is contained in:
Calcitem 2021-01-13 01:15:11 +08:00
parent 1ae4d49fa6
commit effab83b44
2 changed files with 22 additions and 5 deletions

View File

@ -405,15 +405,24 @@ void Position::do_move(Move m)
switch (mt) {
case MOVETYPE_REMOVE:
// Reset rule 50 counter
st.rule50 = 0;
ret = remove_piece(to_sq(m));
if (ret) {
// Reset rule 50 counter
st.rule50 = 0;
}
break;
case MOVETYPE_MOVE:
ret = move_piece(from_sq(m), to_sq(m));
if (ret) {
++st.rule50;
}
break;
case MOVETYPE_PLACE:
ret = put_piece(to_sq(m));
if (ret) {
// Reset rule 50 counter
st.rule50 = 0;
}
break;
default:
break;
@ -423,10 +432,8 @@ void Position::do_move(Move m)
return;
}
// Increment ply counters. In particular, rule50 will be reset to zero later on
// in case of a remove.
// Increment ply counters. In particular
++gamePly;
++st.rule50;
++st.pliesFromNull;
move = m;

View File

@ -111,6 +111,9 @@ int Thread::search()
if (rootPos->get_phase() == Phase::placing) {
posKeyHistory.clear();
rootPos->st.rule50 = 0;
} else if (rootPos->get_phase() == Phase::moving) {
rootPos->st.rule50 = (int)posKeyHistory.size();
}
@ -201,6 +204,13 @@ Value search(Position *pos, Sanmill::Stack<Position> &ss, Depth depth, Depth ori
Depth epsilon;
if (pos->rule50_count() > 99) {
alpha = VALUE_DRAW;
if (alpha >= beta) {
return alpha;
}
}
#ifdef THREEFOLD_REPETITION
// Check if we have an upcoming move which draws by repetition, or
// if the opponent had an alternative move earlier to this position.