]> git.sesse.net Git - stockfish/commitdiff
Assorted trivial cleanups January 2020
authorStéphane Nicolet <cassio@free.fr>
Thu, 9 Jan 2020 19:49:13 +0000 (20:49 +0100)
committerStéphane Nicolet <cassio@free.fr>
Thu, 9 Jan 2020 20:57:21 +0000 (21:57 +0100)
Assorted trivial cleanups.

No functional change

src/endgame.cpp
src/evaluate.cpp
src/position.cpp
src/position.h
src/syzygy/tbprobe.cpp

index 276b942eac55642a3ac3212b6152f797462816bc..2ed6ebc27b78a2a9de0428886ec7503cdb233c0f 100644 (file)
@@ -155,7 +155,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
   Square loserKSq = pos.square<KING>(weakSide);
   Square bishopSq = pos.square<BISHOP>(strongSide);
 
   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
   // to drive to opposite corners (A8/H1).
 
   Value result =  VALUE_KNOWN_WIN
@@ -167,7 +167,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
 }
 
 
 }
 
 
-/// 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 {
 
 template<>
 Value Endgame<KPK>::operator()(const Position& pos) const {
 
index 3a4adef300684cbc1aa7069382068b12f2c19e55..7c7ce95cebcf27d72960c0d34d45857e3d10f052 100644 (file)
@@ -317,20 +317,19 @@ namespace {
                 // 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;
                 // 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;
+                }
             }
         }
 
             }
         }
 
index 7c226deec40e3cb85efe5e31341ced6b79a014d9..53d9b64e9ff0be947b4525433d32f360807d09b5 100644 (file)
@@ -817,7 +817,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
           st->nonPawnMaterial[us] += PieceValue[MG][promotion];
       }
 
           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
       st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
 
       // Reset rule 50 draw counter
@@ -944,7 +944,7 @@ void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Squ
 }
 
 
 }
 
 
-/// 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) {
 /// the side to move without executing any move on the board.
 
 void Position::do_null_move(StateInfo& newSt) {
@@ -1027,16 +1027,16 @@ bool Position::see_ge(Move m, Value threshold) const {
   if (swap <= 0)
       return true;
 
   if (swap <= 0)
       return true;
 
-  Bitboard occ = pieces() ^ from ^ to;
+  Bitboard occupied = pieces() ^ from ^ to;
   Color stm = color_of(piece_on(from));
   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;
   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)))
 
       // If stm has no more attackers then give up: stm loses
       if (!(stmAttackers = attackers & pieces(stm)))
@@ -1044,7 +1044,7 @@ bool Position::see_ge(Move m, Value threshold) const {
 
       // Don't allow pinned pieces to attack (except the king) as long as
       // there are pinners on their original square.
 
       // 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)
           stmAttackers &= ~st->blockersForKing[stm];
 
       if (!stmAttackers)
@@ -1059,8 +1059,8 @@ bool Position::see_ge(Move m, Value threshold) const {
           if ((swap = PawnValueMg - swap) < res)
               break;
 
           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)))
       }
 
       else if ((bb = stmAttackers & pieces(KNIGHT)))
@@ -1068,7 +1068,7 @@ bool Position::see_ge(Move m, Value threshold) const {
           if ((swap = KnightValueMg - swap) < res)
               break;
 
           if ((swap = KnightValueMg - swap) < res)
               break;
 
-          occ ^= lsb(bb);
+          occupied ^= lsb(bb);
       }
 
       else if ((bb = stmAttackers & pieces(BISHOP)))
       }
 
       else if ((bb = stmAttackers & pieces(BISHOP)))
@@ -1076,8 +1076,8 @@ bool Position::see_ge(Move m, Value threshold) const {
           if ((swap = BishopValueMg - swap) < res)
               break;
 
           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)))
       }
 
       else if ((bb = stmAttackers & pieces(ROOK)))
@@ -1085,8 +1085,8 @@ bool Position::see_ge(Move m, Value threshold) const {
           if ((swap = RookValueMg - swap) < res)
               break;
 
           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)))
       }
 
       else if ((bb = stmAttackers & pieces(QUEEN)))
@@ -1094,9 +1094,9 @@ bool Position::see_ge(Move m, Value threshold) const {
           if ((swap = QueenValueMg - swap) < res)
               break;
 
           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
       }
 
       else // KING
@@ -1105,7 +1105,7 @@ bool Position::see_ge(Move m, Value threshold) const {
           return (attackers & ~pieces(stm)) ? res ^ 1 : res;
   }
 
           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
 }
 
 /// Position::is_draw() tests whether the position is drawn by 50-move rule
index 783bb4a3c33fb480cdac41ac52c26ca6aff47972..6791455fd00bc1f83f7fc42752ac0f044179bfed 100644 (file)
@@ -46,7 +46,6 @@ struct StateInfo {
   Square epSquare;
 
   // Not copied when making a move (will be recomputed anyhow)
   Square epSquare;
 
   // Not copied when making a move (will be recomputed anyhow)
-  int repetition;
   Key        key;
   Bitboard   checkersBB;
   Piece      capturedPiece;
   Key        key;
   Bitboard   checkersBB;
   Piece      capturedPiece;
@@ -54,6 +53,7 @@ struct StateInfo {
   Bitboard   blockersForKing[COLOR_NB];
   Bitboard   pinners[COLOR_NB];
   Bitboard   checkSquares[PIECE_TYPE_NB];
   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
 };
 
 /// A list to keep track of the position states along the setup moves (from the
@@ -277,10 +277,14 @@ inline int Position::castling_rights(Color c) const {
 }
 
 inline bool Position::castling_impeded(CastlingRights cr) const {
 }
 
 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 {
   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];
 }
 
   return castlingRookSquare[cr];
 }
 
index 99f1834b498973cb5ee1970e3ff2e18e7f5fdfc8..721a0ef5ba62fc950af0877fc961f0f24a229bf1 100644 (file)
@@ -683,7 +683,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
     bool blackStronger = (pos.material_key() != entry->key);
 
     int flipColor   = (symmetricBlackToMove || blackStronger) * 8;
     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
     int stm         = (symmetricBlackToMove || blackStronger) ^ pos.side_to_move();
 
     // For pawns, TB files store 4 separate tables according if leading pawn is on
@@ -762,7 +762,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
     // piece is below RANK_5.
     if (rank_of(squares[0]) > RANK_4)
         for (int i = 0; i < size; ++i)
     // 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.
 
     // Look for the first piece of the leading group not on the A1-D4 diagonal
     // and ensure it is mapped below the diagonal.