]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Ensure ttValue != VALUE_NONE in singular extension search
[stockfish] / src / position.cpp
index 982352c51b74bbde4f91d0f4f34f8a84e78c33e8..bdbfea8017583fe3b8ca432738bc54a6dec886af 100644 (file)
@@ -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,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