parent
342fd6385b
commit
2408243cf4
|
@ -1229,35 +1229,25 @@ Value Position::compute_non_pawn_material(Color c) const {
|
|||
}
|
||||
|
||||
|
||||
/// Position::is_draw() tests whether the position is drawn by material,
|
||||
/// repetition, or the 50 moves rule. It does not detect stalemates: this
|
||||
/// must be done by the search.
|
||||
/// Position::is_draw() tests whether the position is drawn by material, 50 moves
|
||||
/// rule or repetition. It does not detect stalemates.
|
||||
|
||||
bool Position::is_draw() const {
|
||||
|
||||
// Draw by material?
|
||||
if ( !pieces(PAWN)
|
||||
&& (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg))
|
||||
return true;
|
||||
|
||||
// Draw by the 50 moves rule?
|
||||
if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
|
||||
return true;
|
||||
|
||||
int i = 4, e = std::min(st->rule50, st->pliesFromNull);
|
||||
|
||||
if (i <= e)
|
||||
StateInfo* stp = st;
|
||||
for (int i = 2, e = std::min(st->rule50, st->pliesFromNull); i <= e; i += 2)
|
||||
{
|
||||
StateInfo* stp = st->previous->previous;
|
||||
stp = stp->previous->previous;
|
||||
|
||||
do {
|
||||
stp = stp->previous->previous;
|
||||
|
||||
if (stp->key == st->key)
|
||||
return true; // Draw after first repetition
|
||||
|
||||
i += 2;
|
||||
|
||||
} while (i <= e);
|
||||
if (stp->key == st->key)
|
||||
return true; // Draw at first repetition
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue