+/// Position::game_phase() calculates the game phase of the position
+
+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));
+}
+
+