X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=bdbfea8017583fe3b8ca432738bc54a6dec886af;hp=e2a59e5df3b44eee261e530261a1134bd3ea738f;hb=43efd7fad77eb6a84305b0e2b25e62a6f1ce5fed;hpb=3b315c9adab141830a81afbdff70c18336763e51 diff --git a/src/position.cpp b/src/position.cpp index e2a59e5d..bdbfea80 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -465,15 +465,16 @@ const string Position::pretty(Move m) const { } -/// Position::game_phase() calculates the game phase of the position +/// Position::game_phase() calculates the game phase interpolating total non-pawn +/// material between endgame and midgame limits. Phase Position::game_phase() const { Value npm = st->npMaterial[WHITE] + st->npMaterial[BLACK]; - return npm >= MidgameLimit ? PHASE_MIDGAME - : npm <= EndgameLimit ? PHASE_ENDGAME - : Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit)); + npm = std::max(EndgameLimit, std::min(npm, MidgameLimit)); + + return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit)); }