From 43efd7fad77eb6a84305b0e2b25e62a6f1ce5fed Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 21 Jun 2014 00:02:43 +0200 Subject: [PATCH] Better value clipping in game_phase() No functional change. --- src/position.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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)); } -- 2.39.2