X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=0be309ee60cac3d0ea78bcec0ad6c38237e7768b;hp=c0e2232c08dee5c92c235d24408c99866dee88a3;hb=255df4ffae29f4a038c9881c1f2f675e2f21f71e;hpb=759b3c79cf94d101163f646b1eb2a9f9c64293ab diff --git a/src/position.cpp b/src/position.cpp index c0e2232c..0be309ee 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1105,6 +1105,35 @@ bool Position::is_draw(int ply) const { } +// Position::has_repeated() tests whether there has been at least one repetition +// of positions since the last capture or pawn move. + +bool Position::has_repeated() const { + + StateInfo* stc = st; + while (true) + { + int i = 4, e = std::min(stc->rule50, stc->pliesFromNull); + + if (e < i) + return false; + + StateInfo* stp = st->previous->previous; + + do { + stp = stp->previous->previous; + + if (stp->key == stc->key) + return true; + + i += 2; + } while (i <= e); + + stc = stc->previous; + } +} + + /// Position::flip() flips position with the white and black sides reversed. This /// is only useful for debugging e.g. for finding evaluation symmetry bugs.