X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fposition.cpp;h=e2a59e5df3b44eee261e530261a1134bd3ea738f;hb=3b315c9adab141830a81afbdff70c18336763e51;hp=982352c51b74bbde4f91d0f4f34f8a84e78c33e8;hpb=86c20416c85ac93ab982dda404fc268a92636fa6;p=stockfish diff --git a/src/position.cpp b/src/position.cpp index 982352c5..e2a59e5d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -226,7 +226,7 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) { incremented after Black's move. */ - char col, row, token; + unsigned char col, row, token; size_t idx; Square sq = SQ_A8; std::istringstream ss(fenStr); @@ -465,6 +465,18 @@ const string Position::pretty(Move m) const { } +/// 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)); +} + + /// 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