X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=23370ca3f73d4ed8fedbd14595c8b30af2b332b7;hp=788a220769c23cde1e1a15ce1298d8c32651e44f;hb=888a1d34454121c3682cbd68751bcebeca8bd308;hpb=5f12069cbfc882fdf989d04618ad9c33e603c419 diff --git a/src/position.cpp b/src/position.cpp index 788a2207..23370ca3 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -25,7 +25,6 @@ #include "bitcount.h" #include "movegen.h" -#include "notation.h" #include "position.h" #include "psqtab.h" #include "rkiss.h" @@ -226,7 +225,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); @@ -297,7 +296,7 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) { // Convert from fullmove starting from 1 to ply starting from 0, // handle also common incorrect FEN with fullmove = 0. - gamePly = std::max(2 * (gamePly - 1), 0) + int(sideToMove == BLACK); + gamePly = std::max(2 * (gamePly - 1), 0) + (sideToMove == BLACK); chess960 = isChess960; thisThread = th; @@ -388,21 +387,21 @@ const string Position::fen() const { int emptyCnt; std::ostringstream ss; - for (Rank rank = RANK_8; rank >= RANK_1; --rank) + for (Rank r = RANK_8; r >= RANK_1; --r) { - for (File file = FILE_A; file <= FILE_H; ++file) + for (File f = FILE_A; f <= FILE_H; ++f) { - for (emptyCnt = 0; file <= FILE_H && empty(make_square(file, rank)); ++file) + for (emptyCnt = 0; f <= FILE_H && empty(make_square(f, r)); ++f) ++emptyCnt; if (emptyCnt) ss << emptyCnt; - if (file <= FILE_H) - ss << PieceToChar[piece_on(make_square(file, rank))]; + if (f <= FILE_H) + ss << PieceToChar[piece_on(make_square(f, r))]; } - if (rank > RANK_1) + if (r > RANK_1) ss << '/'; } @@ -424,49 +423,51 @@ const string Position::fen() const { ss << '-'; ss << (ep_square() == SQ_NONE ? " - " : " " + to_string(ep_square()) + " ") - << st->rule50 << " " << 1 + (gamePly - int(sideToMove == BLACK)) / 2; + << st->rule50 << " " << 1 + (gamePly - (sideToMove == BLACK)) / 2; return ss.str(); } -/// Position::pretty() returns an ASCII representation of the position to be -/// printed to the standard output together with the move's san notation. +/// Position::pretty() returns an ASCII representation of the position -const string Position::pretty(Move move) const { +const string Position::pretty() const { - const string dottedLine = "\n+---+---+---+---+---+---+---+---+"; - const string twoRows = dottedLine + "\n| | . | | . | | . | | . |" - + dottedLine + "\n| . | | . | | . | | . | |"; + std::ostringstream ss; - string brd = twoRows + twoRows + twoRows + twoRows + dottedLine; + ss << "\n +---+---+---+---+---+---+---+---+\n"; - for (Bitboard b = pieces(); b; ) + for (Rank r = RANK_8; r >= RANK_1; --r) { - Square s = pop_lsb(&b); - brd[513 - 68 * rank_of(s) + 4 * file_of(s)] = PieceToChar[piece_on(s)]; - } + for (File f = FILE_A; f <= FILE_H; ++f) + ss << " | " << PieceToChar[piece_on(make_square(f, r))]; - std::ostringstream ss; - - if (move) - ss << "\nMove: " << (sideToMove == BLACK ? ".." : "") - << move_to_san(*const_cast(this), move); + ss << " |\n +---+---+---+---+---+---+---+---+\n"; + } - ss << brd << "\nFen: " << fen() << "\nKey: " << std::hex << std::uppercase + ss << "\nFen: " << fen() << "\nKey: " << std::hex << std::uppercase << std::setfill('0') << std::setw(16) << st->key << "\nCheckers: "; for (Bitboard b = checkers(); b; ) ss << to_string(pop_lsb(&b)) << " "; - ss << "\nLegal moves: "; - for (MoveList it(*this); *it; ++it) - ss << move_to_san(*const_cast(this), *it) << " "; - return ss.str(); } +/// 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 @@ -823,7 +824,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI k ^= Zobrist::enpassant[file_of(st->epSquare)]; } - if (type_of(m) == PROMOTION) + else if (type_of(m) == PROMOTION) { PieceType promotion = promotion_type(m); @@ -1147,9 +1148,9 @@ void Position::flip() { string f, token; std::stringstream ss(fen()); - for (Rank rank = RANK_8; rank >= RANK_1; --rank) // Piece placement + for (Rank r = RANK_8; r >= RANK_1; --r) // Piece placement { - std::getline(ss, token, rank > RANK_1 ? '/' : ' '); + std::getline(ss, token, r > RANK_1 ? '/' : ' '); f.insert(0, token + (f.empty() ? " " : "/")); }