X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=bdbfea8017583fe3b8ca432738bc54a6dec886af;hp=2d5119389b989c0719c1514dd330ad7ddbeeca81;hb=e8baf2b772ba8b5eacccd2a64f33faa3b0efa7a8;hpb=4d30126e4b0a64c517fb52ec4c24afdc2645663b diff --git a/src/position.cpp b/src/position.cpp index 2d511938..bdbfea80 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -465,6 +465,19 @@ const string Position::pretty(Move m) const { } +/// 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]; + + npm = std::max(EndgameLimit, std::min(npm, MidgameLimit)); + + return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit)); +} + + /// Position::check_blockers() returns a bitboard of all the pieces with color /// 'c' that are blocking check on the king with color 'kingColor'. A piece /// blocks a check if removing that piece from the board would result in a