X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=cbaa07e86e6c7925aa810347fc63688f63810252;hp=982352c51b74bbde4f91d0f4f34f8a84e78c33e8;hb=15e21911110f9d459c4fef2bb17903d97345d0b9;hpb=86c20416c85ac93ab982dda404fc268a92636fa6 diff --git a/src/position.cpp b/src/position.cpp index 982352c5..cbaa07e8 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); @@ -430,17 +430,12 @@ const string Position::fen() const { } -/// 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 m) const { +const string Position::pretty() const { std::ostringstream ss; - if (m) - ss << "\nMove: " << (sideToMove == BLACK ? ".." : "") - << move_to_san(*const_cast(this), m); - ss << "\n +---+---+---+---+---+---+---+---+\n"; for (Rank r = RANK_8; r >= RANK_1; --r) @@ -457,14 +452,23 @@ const string Position::pretty(Move m) const { 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 @@ -803,9 +807,6 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st->castlingRights &= ~cr; } - // Prefetch TT access as soon as we know the new hash key - prefetch((char*)TT.first_entry(k)); - // Move the piece. The tricky Chess960 castling is handled earlier if (type_of(m) != CASTLING) move_piece(from, to, us, pt); @@ -1012,6 +1013,26 @@ void Position::undo_null_move() { } +/// Position::key_after() computes the new hash key after the given moven. Needed +/// for speculative prefetch. It doesn't recognize special moves like castling, +/// en-passant and promotions. + +Key Position::key_after(Move m) const { + + Color us = sideToMove; + Square from = from_sq(m); + Square to = to_sq(m); + PieceType pt = type_of(piece_on(from)); + PieceType captured = type_of(piece_on(to)); + Key k = st->key ^ Zobrist::side; + + if (captured) + k ^= Zobrist::psq[~us][captured][to]; + + return k ^ Zobrist::psq[us][pt][to] ^ Zobrist::psq[us][pt][from]; +} + + /// Position::see() is a static exchange evaluator: It tries to estimate the /// material gain or loss resulting from a move. @@ -1113,10 +1134,6 @@ Value Position::see(Move m) const { bool Position::is_draw() const { - if ( !pieces(PAWN) - && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg)) - return true; - if (st->rule50 > 99 && (!checkers() || MoveList(*this).size())) return true;