]> git.sesse.net Git - stockfish/commitdiff
Rename castling flag to castling right
authorMarco Costalba <mcostalba@gmail.com>
Sat, 8 Mar 2014 14:08:55 +0000 (15:08 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 8 Mar 2014 14:08:55 +0000 (15:08 +0100)
This is a more conventional naming as
reported also in:

http://chessprogramming.wikispaces.com/Castling+rights

No functional change.

src/movegen.cpp
src/pawns.cpp
src/pawns.h
src/position.cpp
src/position.h
src/types.h

index 39c372924a322dcd676666e34f8222d5c7c74520..5b462c66879e42a06d42018dffda75ba2bc17231 100644 (file)
                                          (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);
 
@@ -264,13 +264,13 @@ namespace {
     {
         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);
         }
     }
 
index 5a5ebb5d1ffa127f897abcb066086ac15269318f..88c63ce3a3d4ad518720d887cdb7fab974f92b16 100644 (file)
@@ -278,7 +278,7 @@ template<Color Us>
 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<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]);
index a84276f82e7036771b59cf2a606a53e4097864d1..525a6dccd043d85a88278508519b1e9e02317025 100644 (file)
@@ -48,7 +48,7 @@ struct Entry {
   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);
   }
 
@@ -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];
index dcd3eb2485316441a986f785b761588cbe0b77d2..cb0701524af47239812f12e887fa502e3c807438 100644 (file)
@@ -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;
           }
 
index 527e66e8b623073764f43d7569b7f305d0f15945..baf49705db7a6e00034a9ed9f561f267fda9b9cc 100644 (file)
@@ -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<PieceType Pt>
index f041e29db5102c7defa5ad8a250d20b2309d76c4..5002ece8c8dd202bd0fcf7a12bbd1c35d6f38368 100644 (file)
@@ -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<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 {
@@ -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) {