X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=0be309ee60cac3d0ea78bcec0ad6c38237e7768b;hp=9cec2c14ff9646882a06f3abd02290248196d8f2;hb=108f0da4d7f993732aa2e854b8f3fa8ca6d3b46c;hpb=96362fe3df141eeead4bdb863d2bb2d891886abf diff --git a/src/position.cpp b/src/position.cpp index 9cec2c14..0be309ee 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -52,8 +52,8 @@ namespace { const string PieceToChar(" PNBRQK pnbrqk"); -const Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING, - B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING }; +constexpr Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING, + B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING }; // min_attacker() is a helper function used by see_ge() to locate the least // valuable attacker for the side to move, remove the attacker we just found @@ -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. @@ -1146,7 +1175,7 @@ void Position::flip() { bool Position::pos_is_ok() const { - const bool Fast = true; // Quick (default) or full check? + constexpr bool Fast = true; // Quick (default) or full check? if ( (sideToMove != WHITE && sideToMove != BLACK) || piece_on(square(WHITE)) != W_KING