(mlist++)->move = make_move(to - (d), to); }
namespace {
- template<CastlingFlag Cf, bool Checks, bool Chess960>
+ template<CastlingRight Cr, bool Checks, bool Chess960>
ExtMove* generate_castling(const Position& pos, ExtMove* mlist, Color us, const CheckInfo* ci) {
- static const bool KingSide = (Cf == WHITE_OO || Cf == BLACK_OO);
+ static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
- if (pos.castling_impeded(Cf) || !pos.can_castle(Cf))
+ if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
return mlist;
// After castling, the rook and king final positions are the same in Chess960
// as they would be in standard chess.
Square kfrom = pos.king_square(us);
- Square rfrom = pos.castling_rook_square(Cf);
+ Square rfrom = pos.castling_rook_square(Cr);
Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1);
Bitboard enemies = pos.pieces(~us);
{
if (pos.is_chess960())
{
- mlist = generate_castling<MakeCastling<Us, KING_SIDE>::flag, Checks, true>(pos, mlist, Us, ci);
- mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::flag, Checks, true>(pos, mlist, Us, ci);
+ mlist = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, mlist, Us, ci);
+ mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, mlist, Us, ci);
}
else
{
- mlist = generate_castling<MakeCastling<Us, KING_SIDE>::flag, Checks, false>(pos, mlist, Us, ci);
- mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::flag, Checks, false>(pos, mlist, Us, ci);
+ mlist = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, mlist, Us, ci);
+ mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, mlist, Us, ci);
}
}
Score Entry::update_safety(const Position& pos, Square ksq) {
kingSquares[Us] = ksq;
- castlingFlags[Us] = pos.can_castle(Us);
+ castlingRights[Us] = pos.can_castle(Us);
minKPdistance[Us] = 0;
Bitboard pawns = pos.pieces(Us, PAWN);
Value bonus = shelter_storm<Us>(pos, ksq);
// If we can castle use the bonus after the castling if it is bigger
- if (pos.can_castle(MakeCastling<Us, KING_SIDE>::flag))
+ if (pos.can_castle(MakeCastling<Us, KING_SIDE>::right))
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_G1)));
- if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::flag))
+ if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::right))
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1)));
return kingSafety[Us] = make_score(bonus, -16 * minKPdistance[Us]);
template<Color Us>
Score king_safety(const Position& pos, Square ksq) {
- return kingSquares[Us] == ksq && castlingFlags[Us] == pos.can_castle(Us)
+ return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
? kingSafety[Us] : update_safety<Us>(pos, ksq);
}
Bitboard pawnAttacks[COLOR_NB];
Square kingSquares[COLOR_NB];
int minKPdistance[COLOR_NB];
- int castlingFlags[COLOR_NB];
+ int castlingRights[COLOR_NB];
Score value;
int semiopenFiles[COLOR_NB];
Score kingSafety[COLOR_NB];
Key psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
Key enpassant[FILE_NB];
- Key castling[CASTLING_FLAG_NB];
+ Key castling[CASTLING_RIGHT_NB];
Key side;
Key exclusion;
}
else
continue;
- set_castling_flag(c, rsq);
+ set_castling_right(c, rsq);
}
// 4. En passant square. Ignore if no pawn capture is possible
}
-/// Position::set_castling_flag() is a helper function used to set castling
-/// flags given the corresponding color and the rook starting square.
+/// Position::set_castling_right() is a helper function used to set castling
+/// rights given the corresponding color and the rook starting square.
-void Position::set_castling_flag(Color c, Square rfrom) {
+void Position::set_castling_right(Color c, Square rfrom) {
Square kfrom = king_square(c);
CastlingSide cs = kfrom < rfrom ? KING_SIDE : QUEEN_SIDE;
- CastlingFlag cf = (c | cs);
+ CastlingRight cr = (c | cs);
- st->castlingFlags |= cf;
- castlingFlagsMask[kfrom] |= cf;
- castlingFlagsMask[rfrom] |= cf;
- castlingRookSquare[cf] = rfrom;
+ st->castlingRights |= cr;
+ castlingRightsMask[kfrom] |= cr;
+ castlingRightsMask[rfrom] |= cr;
+ castlingRookSquare[cr] = rfrom;
Square kto = relative_square(c, cs == KING_SIDE ? SQ_G1 : SQ_C1);
Square rto = relative_square(c, cs == KING_SIDE ? SQ_F1 : SQ_D1);
for (Square s = std::min(rfrom, rto); s <= std::max(rfrom, rto); ++s)
if (s != kfrom && s != rfrom)
- castlingPath[cf] |= s;
+ castlingPath[cr] |= s;
for (Square s = std::min(kfrom, kto); s <= std::max(kfrom, kto); ++s)
if (s != kfrom && s != rfrom)
- castlingPath[cf] |= s;
+ castlingPath[cr] |= s;
}
st->epSquare = SQ_NONE;
}
- // Update castling flags if needed
- if (st->castlingFlags && (castlingFlagsMask[from] | castlingFlagsMask[to]))
+ // Update castling rights if needed
+ if (st->castlingRights && (castlingRightsMask[from] | castlingRightsMask[to]))
{
- int cf = castlingFlagsMask[from] | castlingFlagsMask[to];
- k ^= Zobrist::castling[st->castlingFlags & cf];
- st->castlingFlags &= ~cf;
+ int cr = castlingRightsMask[from] | castlingRightsMask[to];
+ k ^= Zobrist::castling[st->castlingRights & cr];
+ st->castlingRights &= ~cr;
}
// Prefetch TT access as soon as we know the new hash key
Key Position::compute_key() const {
- Key k = Zobrist::castling[st->castlingFlags];
+ Key k = Zobrist::castling[st->castlingRights];
for (Bitboard b = pieces(); b; )
{
if (!can_castle(c | s))
continue;
- if ( (castlingFlagsMask[king_square(c)] & (c | s)) != (c | s)
+ if ( (castlingRightsMask[king_square(c)] & (c | s)) != (c | s)
|| piece_on(castlingRookSquare[c | s]) != make_piece(c, ROOK)
- || castlingFlagsMask[castlingRookSquare[c | s]] != (c | s))
+ || castlingRightsMask[castlingRookSquare[c | s]] != (c | s))
return false;
}
struct StateInfo {
Key pawnKey, materialKey;
Value npMaterial[COLOR_NB];
- int castlingFlags, rule50, pliesFromNull;
+ int castlingRights, rule50, pliesFromNull;
Score psq;
Square epSquare;
// Castling
int can_castle(Color c) const;
- int can_castle(CastlingFlag f) const;
- bool castling_impeded(CastlingFlag f) const;
- Square castling_rook_square(CastlingFlag f) const;
+ int can_castle(CastlingRight cr) const;
+ bool castling_impeded(CastlingRight cr) const;
+ Square castling_rook_square(CastlingRight cr) const;
// Checking
Bitboard checkers() const;
private:
// Initialization helpers (used while setting up a position)
void clear();
- void set_castling_flag(Color c, Square rfrom);
+ void set_castling_right(Color c, Square rfrom);
// Helper functions
void do_castling(Square kfrom, Square kto, Square rfrom, Square rto);
int index[SQUARE_NB];
// Other info
- int castlingFlagsMask[SQUARE_NB];
- Square castlingRookSquare[CASTLING_FLAG_NB];
- Bitboard castlingPath[CASTLING_FLAG_NB];
+ int castlingRightsMask[SQUARE_NB];
+ Square castlingRookSquare[CASTLING_RIGHT_NB];
+ Bitboard castlingPath[CASTLING_RIGHT_NB];
StateInfo startState;
uint64_t nodes;
int gamePly;
return pieceList[c][KING][0];
}
-inline int Position::can_castle(CastlingFlag f) const {
- return st->castlingFlags & f;
+inline int Position::can_castle(CastlingRight cr) const {
+ return st->castlingRights & cr;
}
inline int Position::can_castle(Color c) const {
- return st->castlingFlags & ((WHITE_OO | WHITE_OOO) << (2 * c));
+ return st->castlingRights & ((WHITE_OO | WHITE_OOO) << (2 * c));
}
-inline bool Position::castling_impeded(CastlingFlag f) const {
- return byTypeBB[ALL_PIECES] & castlingPath[f];
+inline bool Position::castling_impeded(CastlingRight cr) const {
+ return byTypeBB[ALL_PIECES] & castlingPath[cr];
}
-inline Square Position::castling_rook_square(CastlingFlag f) const {
- return castlingRookSquare[f];
+inline Square Position::castling_rook_square(CastlingRight cr) const {
+ return castlingRookSquare[cr];
}
template<PieceType Pt>
KING_SIDE, QUEEN_SIDE, CASTLING_SIDE_NB = 2
};
-enum CastlingFlag { // Defined as in PolyGlot book hash key
+enum CastlingRight { // Defined as in PolyGlot book hash key
NO_CASTLING,
WHITE_OO,
WHITE_OOO = WHITE_OO << 1,
BLACK_OO = WHITE_OO << 2,
BLACK_OOO = WHITE_OO << 3,
ANY_CASTLING = WHITE_OO | WHITE_OOO | BLACK_OO | BLACK_OOO,
- CASTLING_FLAG_NB = 16
+ CASTLING_RIGHT_NB = 16
};
template<Color C, CastlingSide S> struct MakeCastling {
- static const CastlingFlag
- flag = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO
- : S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO;
+ static const CastlingRight
+ right = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO
+ : S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO;
};
enum Phase {
return Square((r << 3) | f);
}
-inline CastlingFlag operator|(Color c, CastlingSide s) {
- return CastlingFlag(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
+inline CastlingRight operator|(Color c, CastlingSide s) {
+ return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
}
inline Value mate_in(int ply) {