From: Marco Costalba Date: Sat, 8 Mar 2014 14:08:55 +0000 (+0100) Subject: Rename castling flag to castling right X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=1d1b7df7c6b3496d1a3fe926cadf25d91e1558f6 Rename castling flag to castling right This is a more conventional naming as reported also in: http://chessprogramming.wikispaces.com/Castling+rights No functional change. --- diff --git a/src/movegen.cpp b/src/movegen.cpp index 39c37292..5b462c66 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -31,18 +31,18 @@ (mlist++)->move = make_move(to - (d), to); } namespace { - template + template 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); @@ -264,13 +264,13 @@ namespace { { if (pos.is_chess960()) { - mlist = generate_castling::flag, Checks, true>(pos, mlist, Us, ci); - mlist = generate_castling::flag, Checks, true>(pos, mlist, Us, ci); + mlist = generate_castling::right, Checks, true>(pos, mlist, Us, ci); + mlist = generate_castling::right, Checks, true>(pos, mlist, Us, ci); } else { - mlist = generate_castling::flag, Checks, false>(pos, mlist, Us, ci); - mlist = generate_castling::flag, Checks, false>(pos, mlist, Us, ci); + mlist = generate_castling::right, Checks, false>(pos, mlist, Us, ci); + mlist = generate_castling::right, Checks, false>(pos, mlist, Us, ci); } } diff --git a/src/pawns.cpp b/src/pawns.cpp index 5a5ebb5d..88c63ce3 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -278,7 +278,7 @@ template 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); @@ -291,10 +291,10 @@ Score Entry::update_safety(const Position& pos, Square ksq) { Value bonus = shelter_storm(pos, ksq); // If we can castle use the bonus after the castling if it is bigger - if (pos.can_castle(MakeCastling::flag)) + if (pos.can_castle(MakeCastling::right)) bonus = std::max(bonus, shelter_storm(pos, relative_square(Us, SQ_G1))); - if (pos.can_castle(MakeCastling::flag)) + if (pos.can_castle(MakeCastling::right)) bonus = std::max(bonus, shelter_storm(pos, relative_square(Us, SQ_C1))); return kingSafety[Us] = make_score(bonus, -16 * minKPdistance[Us]); diff --git a/src/pawns.h b/src/pawns.h index a84276f8..525a6dcc 100644 --- a/src/pawns.h +++ b/src/pawns.h @@ -48,7 +48,7 @@ struct Entry { template 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(pos, ksq); } @@ -64,7 +64,7 @@ struct Entry { 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]; diff --git a/src/position.cpp b/src/position.cpp index dcd3eb24..cb070152 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -47,7 +47,7 @@ namespace Zobrist { 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; } @@ -263,7 +263,7 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) { else continue; - set_castling_flag(c, rsq); + set_castling_right(c, rsq); } // 4. En passant square. Ignore if no pawn capture is possible @@ -297,30 +297,30 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) { } -/// 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; } @@ -791,12 +791,12 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI 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 @@ -1128,7 +1128,7 @@ void Position::clear() { Key Position::compute_key() const { - Key k = Zobrist::castling[st->castlingFlags]; + Key k = Zobrist::castling[st->castlingRights]; for (Bitboard b = pieces(); b; ) { @@ -1396,9 +1396,9 @@ bool Position::pos_is_ok(int* failedStep) const { 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; } diff --git a/src/position.h b/src/position.h index 527e66e8..baf49705 100644 --- a/src/position.h +++ b/src/position.h @@ -51,7 +51,7 @@ struct CheckInfo { struct StateInfo { Key pawnKey, materialKey; Value npMaterial[COLOR_NB]; - int castlingFlags, rule50, pliesFromNull; + int castlingRights, rule50, pliesFromNull; Score psq; Square epSquare; @@ -101,9 +101,9 @@ public: // 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; @@ -170,7 +170,7 @@ public: 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); @@ -197,9 +197,9 @@ private: 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; @@ -273,20 +273,20 @@ inline Square Position::king_square(Color c) const { 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 diff --git a/src/types.h b/src/types.h index f041e29d..5002ece8 100644 --- a/src/types.h +++ b/src/types.h @@ -124,20 +124,20 @@ enum CastlingSide { 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 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 { @@ -341,8 +341,8 @@ inline Square operator|(File f, Rank r) { 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) {