]> git.sesse.net Git - stockfish/commitdiff
Introduce make_castle_right() helper
authorMarco Costalba <mcostalba@gmail.com>
Sun, 8 Apr 2012 16:07:56 +0000 (17:07 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 8 Apr 2012 16:19:49 +0000 (17:19 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/movegen.cpp
src/pawns.cpp
src/position.cpp
src/types.h

index ed204672378fa81edeaacf417494982c1ac36b6a..154e69e2207dc504c718050d310254cd9f880da0 100644 (file)
@@ -35,16 +35,14 @@ namespace {
   template<CastlingSide Side, bool OnlyChecks>
   MoveStack* generate_castle(const Position& pos, MoveStack* mlist, Color us) {
 
-    CastleRight cr = CastleRight((Side == KING_SIDE ? WHITE_OO : WHITE_OOO) << us);
-
-    if (pos.castle_impeded(us, Side) || !pos.can_castle(cr))
+    if (pos.castle_impeded(us, Side) || !pos.can_castle(make_castle_right(us, Side)))
         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 kto = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1);
     Square rfrom = pos.castle_rook_square(us, Side);
+    Square kto = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1);
     Bitboard enemies = pos.pieces(~us);
 
     assert(!pos.in_check());
index 795e31e2423941a3a973187d83c2d2b080b353c8..7fd4ac071490dea47b3dc812bf968cc0d15e94b9 100644 (file)
@@ -267,10 +267,10 @@ Score PawnEntry::update_safety(const Position& pos, Square ksq) {
   Value bonus = shelter_storm<Us>(pos, ksq);
 
   // If we can castle use the bonus after the castle if is bigger
-  if (pos.can_castle(Us == WHITE ? WHITE_OO : BLACK_OO))
+  if (pos.can_castle(make_castle_right(Us, KING_SIDE)))
       bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_G1)));
 
-  if (pos.can_castle(Us == WHITE ? WHITE_OOO : BLACK_OOO))
+  if (pos.can_castle(make_castle_right(Us, QUEEN_SIDE)))
       bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1)));
 
   return kingSafety[Us] = make_score(bonus, 0);
index 60c5380d8352e329c2b662e218d75fbb885717cc..8b043af83b4a0826c0d0fe52000bce970cce9c79 100644 (file)
@@ -240,7 +240,7 @@ void Position::set_castle_right(Color c, Square rfrom) {
 
   Square kfrom = king_square(c);
   CastlingSide cs = kfrom < rfrom ? KING_SIDE : QUEEN_SIDE;
-  int cr = (cs == KING_SIDE ? WHITE_OO : WHITE_OOO) << c;
+  CastleRight cr = make_castle_right(c, cs);
 
   st->castleRights |= cr;
   castleRightsMask[kfrom] |= cr;
@@ -1727,15 +1727,13 @@ bool Position::pos_is_ok(int* failedStep) const {
   if (failedStep) (*failedStep)++;
   if (debugCastleSquares)
       for (Color c = WHITE; c <= BLACK; c++)
-          for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s+1))
+          for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s + 1))
           {
-              CastleRight cr = CastleRight((s == KING_SIDE ? WHITE_OO : WHITE_OOO) << c);
-
-              if (!can_castle(cr))
+              if (!can_castle(make_castle_right(c, s)))
                   continue;
 
               if (   piece_on(castleRookSquare[c][s]) != make_piece(c, ROOK)
-                  || castleRightsMask[castleRookSquare[c][s]] != cr)
+                  || castleRightsMask[castleRookSquare[c][s]] != make_castle_right(c, s))
                   return false;
           }
 
index a9b95a0ab86d0f7181be901e68907dfe60339fe8..5b5bc1f227785d6a80b1d7a57e936bfd44df6cae 100644 (file)
@@ -347,6 +347,10 @@ inline Piece make_piece(Color c, PieceType pt) {
   return Piece((c << 3) | pt);
 }
 
+inline CastleRight make_castle_right(Color c, CastlingSide s) {
+  return CastleRight((s == KING_SIDE ? WHITE_OO : WHITE_OOO) << c);
+}
+
 inline PieceType type_of(Piece p)  {
   return PieceType(p & 7);
 }