/// 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.
-template<bool SkipRepetition>
+template<bool SkipRepetition, bool SkipThreeFoldCheck>
bool Position::is_draw() const {
// Draw by material?
// Draw by repetition?
if (!SkipRepetition)
{
- int i = 4, e = std::min(st->rule50, st->pliesFromNull);
+ int i = 4, e = std::min(st->rule50, st->pliesFromNull), rep_count=0;
if (i <= e)
{
stp = stp->previous->previous;
if (stp->key == st->key)
- return true;
+ {
+ if(SkipThreeFoldCheck) return true;
+ else if(++rep_count>=2) return true;
+ }
i +=2;
}
// Explicit template instantiations
-template bool Position::is_draw<false>() const;
-template bool Position::is_draw<true>() const;
+template bool Position::is_draw<false,true>() const;
+template bool Position::is_draw<true,true>() const;
+template bool Position::is_draw<false,false>() const;
/// Position::flip() flips position with the white and black sides reversed. This
Thread* this_thread() const;
int64_t nodes_searched() const;
void set_nodes_searched(int64_t n);
- template<bool SkipRepetition> bool is_draw() const;
+ template<bool SkipRepetition, bool SkipThreeFoldCheck> bool is_draw() const;
// Position consistency check, for debugging
bool pos_is_ok(int* failedStep = NULL) const;
if (!RootNode)
{
// Step 2. Check for aborted search and immediate draw
- if (Signals.stop || pos.is_draw<false>() || ss->ply > MAX_PLY)
+ if (Signals.stop || pos.is_draw<false,true>() || ss->ply > MAX_PLY)
return DrawValue[pos.side_to_move()];
// Step 3. Mate distance pruning. Even if we mate at the next move our score
ss->ply = (ss-1)->ply + 1;
// Check for an instant draw or maximum ply reached
- if (pos.is_draw<true>() || ss->ply > MAX_PLY)
+ if (pos.is_draw<true,true>() || ss->ply > MAX_PLY)
return DrawValue[pos.side_to_move()];
// Transposition table lookup. At PV nodes, we don't use the TT for
&& pos.is_pseudo_legal(m)
&& pos.pl_move_is_legal(m, pos.pinned_pieces())
&& ply < MAX_PLY
- && (!pos.is_draw<false>() || ply < 2))
+ && (!pos.is_draw<false,true>() || ply < 2))
{
pv.push_back(m);
pos.do_move(m, *st++);