Assorted trivial cleanups.
No functional change
Square loserKSq = pos.square<KING>(weakSide);
Square bishopSq = pos.square<BISHOP>(strongSide);
- // If our Bishop does not attack A1/H8, we flip the enemy king square
+ // If our bishop does not attack A1/H8, we flip the enemy king square
// to drive to opposite corners (A8/H1).
Value result = VALUE_KNOWN_WIN
}
-/// KP vs K. This endgame is evaluated with the help of a bitbase.
+/// KP vs K. This endgame is evaluated with the help of a bitbase
template<>
Value Endgame<KPK>::operator()(const Position& pos) const {
// Bonus for bishop on a long diagonal which can "see" both center squares
if (more_than_one(attacks_bb<BISHOP>(s, pos.pieces(PAWN)) & Center))
score += LongDiagonalBishop;
- }
- // An important Chess960 pattern: A cornered bishop blocked by a friendly
- // pawn diagonally in front of it is a very serious problem, especially
- // when that pawn is also blocked.
- if ( Pt == BISHOP
- && pos.is_chess960()
- && (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
- {
- Direction d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
- if (pos.piece_on(s + d) == make_piece(Us, PAWN))
- score -= !pos.empty(s + d + pawn_push(Us)) ? CorneredBishop * 4
- : pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? CorneredBishop * 2
- : CorneredBishop;
+ // An important Chess960 pattern: a cornered bishop blocked by a friendly
+ // pawn diagonally in front of it is a very serious problem, especially
+ // when that pawn is also blocked.
+ if ( pos.is_chess960()
+ && (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
+ {
+ Direction d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
+ if (pos.piece_on(s + d) == make_piece(Us, PAWN))
+ score -= !pos.empty(s + d + pawn_push(Us)) ? CorneredBishop * 4
+ : pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? CorneredBishop * 2
+ : CorneredBishop;
+ }
}
}
st->nonPawnMaterial[us] += PieceValue[MG][promotion];
}
- // Update pawn hash key and prefetch access to pawnsTable
+ // Update pawn hash key
st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
// Reset rule 50 draw counter
}
-/// Position::do(undo)_null_move() is used to do(undo) a "null move": It flips
+/// Position::do(undo)_null_move() is used to do(undo) a "null move": it flips
/// the side to move without executing any move on the board.
void Position::do_null_move(StateInfo& newSt) {
if (swap <= 0)
return true;
- Bitboard occ = pieces() ^ from ^ to;
+ Bitboard occupied = pieces() ^ from ^ to;
Color stm = color_of(piece_on(from));
- Bitboard attackers = attackers_to(to, occ);
+ Bitboard attackers = attackers_to(to, occupied);
Bitboard stmAttackers, bb;
int res = 1;
while (true)
{
stm = ~stm;
- attackers &= occ;
+ attackers &= occupied;
// If stm has no more attackers then give up: stm loses
if (!(stmAttackers = attackers & pieces(stm)))
// Don't allow pinned pieces to attack (except the king) as long as
// there are pinners on their original square.
- if (st->pinners[~stm] & occ)
+ if (st->pinners[~stm] & occupied)
stmAttackers &= ~st->blockersForKing[stm];
if (!stmAttackers)
if ((swap = PawnValueMg - swap) < res)
break;
- occ ^= lsb(bb);
- attackers |= attacks_bb<BISHOP>(to, occ) & pieces(BISHOP, QUEEN);
+ occupied ^= lsb(bb);
+ attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
}
else if ((bb = stmAttackers & pieces(KNIGHT)))
if ((swap = KnightValueMg - swap) < res)
break;
- occ ^= lsb(bb);
+ occupied ^= lsb(bb);
}
else if ((bb = stmAttackers & pieces(BISHOP)))
if ((swap = BishopValueMg - swap) < res)
break;
- occ ^= lsb(bb);
- attackers |= attacks_bb<BISHOP>(to, occ) & pieces(BISHOP, QUEEN);
+ occupied ^= lsb(bb);
+ attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
}
else if ((bb = stmAttackers & pieces(ROOK)))
if ((swap = RookValueMg - swap) < res)
break;
- occ ^= lsb(bb);
- attackers |= attacks_bb<ROOK>(to, occ) & pieces(ROOK, QUEEN);
+ occupied ^= lsb(bb);
+ attackers |= attacks_bb<ROOK>(to, occupied) & pieces(ROOK, QUEEN);
}
else if ((bb = stmAttackers & pieces(QUEEN)))
if ((swap = QueenValueMg - swap) < res)
break;
- occ ^= lsb(bb);
- attackers |= (attacks_bb<BISHOP>(to, occ) & pieces(BISHOP, QUEEN))
- | (attacks_bb<ROOK >(to, occ) & pieces(ROOK , QUEEN));
+ occupied ^= lsb(bb);
+ attackers |= (attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN))
+ | (attacks_bb<ROOK >(to, occupied) & pieces(ROOK , QUEEN));
}
else // KING
return (attackers & ~pieces(stm)) ? res ^ 1 : res;
}
- return res;
+ return bool(res);
}
/// Position::is_draw() tests whether the position is drawn by 50-move rule
Square epSquare;
// Not copied when making a move (will be recomputed anyhow)
- int repetition;
Key key;
Bitboard checkersBB;
Piece capturedPiece;
Bitboard blockersForKing[COLOR_NB];
Bitboard pinners[COLOR_NB];
Bitboard checkSquares[PIECE_TYPE_NB];
+ int repetition;
};
/// A list to keep track of the position states along the setup moves (from the
}
inline bool Position::castling_impeded(CastlingRights cr) const {
+ assert(cr == WHITE_OO || cr == WHITE_OOO || cr == BLACK_OO || cr == BLACK_OOO);
+
return byTypeBB[ALL_PIECES] & castlingPath[cr];
}
inline Square Position::castling_rook_square(CastlingRights cr) const {
+ assert(cr == WHITE_OO || cr == WHITE_OOO || cr == BLACK_OO || cr == BLACK_OOO);
+
return castlingRookSquare[cr];
}
bool blackStronger = (pos.material_key() != entry->key);
int flipColor = (symmetricBlackToMove || blackStronger) * 8;
- int flipSquares = (symmetricBlackToMove || blackStronger) * 070;
+ int flipSquares = (symmetricBlackToMove || blackStronger) * 56;
int stm = (symmetricBlackToMove || blackStronger) ^ pos.side_to_move();
// For pawns, TB files store 4 separate tables according if leading pawn is on
// piece is below RANK_5.
if (rank_of(squares[0]) > RANK_4)
for (int i = 0; i < size; ++i)
- squares[i] ^= 070; // Vertical flip: SQ_A8 -> SQ_A1
+ squares[i] ^= SQ_A8; // Vertical flip: SQ_A8 -> SQ_A1
// Look for the first piece of the leading group not on the A1-D4 diagonal
// and ensure it is mapped below the diagonal.