// 5-6. Halfmove clock and fullmove number
ss >> std::skipws >> st->rule50 >> gamePly;
- // Convert from fullmove starting from 1 to ply starting from 0,
+ // Convert from fullmove starting from 1 to gamePly starting from 0,
// handle also common incorrect FEN with fullmove = 0.
gamePly = std::max(2 * (gamePly - 1), 0) + (sideToMove == BLACK);
}
-/// 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->nonPawnMaterial[WHITE] + st->nonPawnMaterial[BLACK];
-
- npm = std::max(EndgameLimit, std::min(npm, MidgameLimit));
-
- return Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
-}
-
-
/// Position::slider_blockers() returns a bitboard of all the pieces (both colors)
/// that are blocking attacks on the square 's' from 'sliders'. A piece blocks a
/// slider if removing that piece from the board would result in a position where
assert(is_ok(m));
assert(&newSt != st);
- ++nodes;
+ thisThread->nodes.fetch_add(1, std::memory_order_relaxed);
Key k = st->key ^ Zobrist::side;
// Copy some fields of the old state to our new StateInfo object except the
assert(is_ok(m));
- // Castling moves are implemented as king capturing the rook so cannot be
- // handled correctly. Simply assume the SEE value is VALUE_ZERO that is always
- // correct unless in the rare case the rook ends up under attack.
- if (type_of(m) == CASTLING)
+ // Only deal with normal moves, assume others pass a simple see
+ if (type_of(m) != NORMAL)
return VALUE_ZERO >= threshold;
Square from = from_sq(m), to = to_sq(m);
Value balance; // Values of the pieces taken by us minus opponent's ones
Bitboard occupied, stmAttackers;
- if (type_of(m) == ENPASSANT)
- {
- occupied = SquareBB[to - pawn_push(~stm)]; // Remove the captured pawn
- balance = PieceValue[MG][PAWN];
- }
- else
- {
- balance = PieceValue[MG][piece_on(to)];
- occupied = 0;
- }
+ balance = PieceValue[MG][piece_on(to)];
if (balance < threshold)
return false;
- if (nextVictim == KING)
- return true;
-
balance -= PieceValue[MG][nextVictim];
- if (balance >= threshold)
+ if (balance >= threshold) // Always true if nextVictim == KING
return true;
bool relativeStm = true; // True if the opponent is to move
- occupied ^= pieces() ^ from ^ to;
+ occupied = pieces() ^ from ^ to;
// Find all attackers to the destination square, with the moving piece removed,
// but possibly an X-ray attacker added behind it.
{
stp = stp->previous->previous;
- // At root position ply is 1, so return a draw score if a position
- // repeats once earlier but strictly after the root, or repeats twice
- // before or at the root.
+ // Return a draw score if a position repeats once earlier but strictly
+ // after the root, or repeats twice before or at the root.
if ( stp->key == st->key
- && ++cnt + (ply - 1 > i) == 2)
+ && ++cnt + (ply > i) == 2)
return true;
}