]> git.sesse.net Git - stockfish/commitdiff
Restrict mobility of pinned pieces
authorGary Linscott <glinscott@gmail.com>
Thu, 7 Nov 2013 18:59:11 +0000 (13:59 -0500)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 7 Nov 2013 21:26:03 +0000 (22:26 +0100)
Passed both short TC:
LLR: 3.00 (-2.94,2.94) [-1.50,4.50]
Total: 54342 W: 10950 L: 10692 D: 32700

And long TC:
LLR: 2.95 (-2.94,2.94) [0.00,6.00]
Total: 61976 W: 10654 L: 10251 D: 41071

This patch introduces a slowdown of 3.5 % !!!!!

bench: 7911558

src/evaluate.cpp
src/movegen.cpp
src/notation.cpp
src/position.cpp
src/position.h
src/search.cpp

index 5b1f4f40ce493c0546a8944c7febb8cf717b5048..279802387402906e969f1361eb2051a03a04efe7 100644 (file)
@@ -83,6 +83,8 @@ namespace {
     // king is on g8 and there's a white knight on g5, this knight adds
     // 2 to kingAdjacentZoneAttacksCount[BLACK].
     int kingAdjacentZoneAttacksCount[COLOR_NB];
+
+    Bitboard pinnedPieces[COLOR_NB];
   };
 
   // Evaluation grain size, must be a power of 2
@@ -423,6 +425,8 @@ Value do_evaluate(const Position& pos) {
     const Color  Them = (Us == WHITE ? BLACK : WHITE);
     const Square Down = (Us == WHITE ? DELTA_S : DELTA_N);
 
+    ei.pinnedPieces[Us] = pos.pinned_pieces(Us);
+
     Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from<KING>(pos.king_square(Them));
     ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us);
 
@@ -487,6 +491,9 @@ Value do_evaluate(const Position& pos) {
           : Piece ==   ROOK ? attacks_bb<  ROOK>(s, pos.pieces() ^ pos.pieces(Us, ROOK, QUEEN))
                             : pos.attacks_from<Piece>(s);
 
+        if (ei.pinnedPieces[Us] & s)
+            b &= PseudoAttacks[QUEEN][pos.king_square(Us)];
+
         ei.attackedBy[Us][Piece] |= b;
 
         if (b & ei.kingRing[Them])
index 96dd89c502f1e441e5e5edfa0b55fe1a8f7cbb8b..1524bf1f2453baa1152e9c95874209c91184d04c 100644 (file)
@@ -407,7 +407,7 @@ template<>
 ExtMove* generate<LEGAL>(const Position& pos, ExtMove* mlist) {
 
   ExtMove *end, *cur = mlist;
-  Bitboard pinned = pos.pinned_pieces();
+  Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
   Square ksq = pos.king_square(pos.side_to_move());
 
   end = pos.checkers() ? generate<EVASIONS>(pos, mlist)
index 3f79a44b6290d246a95af9b85506b71aecad0e6a..d017c0790cc801b42842b949eb9c2c85d210e788 100644 (file)
@@ -133,7 +133,7 @@ const string move_to_san(Position& pos, Move m) {
           while (b)
           {
               Move move = make_move(pop_lsb(&b), to);
-              if (!pos.legal(move, pos.pinned_pieces()))
+              if (!pos.legal(move, pos.pinned_pieces(pos.side_to_move())))
                   others ^= from_sq(move);
           }
 
index fade3cbab49d1f27a03912659099a2b3c98097ba..ec008338796cc4b8f422366899ff0e82358fd8d0 100644 (file)
@@ -98,7 +98,7 @@ CheckInfo::CheckInfo(const Position& pos) {
   Color them = ~pos.side_to_move();
   ksq = pos.king_square(them);
 
-  pinned = pos.pinned_pieces();
+  pinned = pos.pinned_pieces(pos.side_to_move());
   dcCandidates = pos.discovered_check_candidates();
 
   checkSq[PAWN]   = pos.attacks_from<PAWN>(ksq, them);
@@ -422,7 +422,7 @@ const string Position::pretty(Move move) const {
 /// pieces, according to the call parameters. Pinned pieces protect our king,
 /// discovery check pieces attack the enemy king.
 
-Bitboard Position::hidden_checkers(Square ksq, Color c) const {
+Bitboard Position::hidden_checkers(Square ksq, Color c, Color toMove) const {
 
   Bitboard b, pinners, result = 0;
 
@@ -435,7 +435,7 @@ Bitboard Position::hidden_checkers(Square ksq, Color c) const {
       b = between_bb(ksq, pop_lsb(&pinners)) & pieces();
 
       if (!more_than_one(b))
-          result |= b & pieces(sideToMove);
+          result |= b & pieces(toMove);
   }
   return result;
 }
@@ -477,7 +477,7 @@ Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) {
 bool Position::legal(Move m, Bitboard pinned) const {
 
   assert(is_ok(m));
-  assert(pinned == pinned_pieces());
+  assert(pinned == pinned_pieces(pos.side_to_move()));
 
   Color us = sideToMove;
   Square from = from_sq(m);
index e73c8ff5d9d3c78406f346f5b7582aef2e4c7f0a..c333e55a63ab859e43d7085f2d80f89e4ab64df6 100644 (file)
@@ -108,7 +108,7 @@ public:
   // Checking
   Bitboard checkers() const;
   Bitboard discovered_check_candidates() const;
-  Bitboard pinned_pieces() const;
+  Bitboard pinned_pieces(Color toMove) const;
 
   // Attacks to/from a given square
   Bitboard attackers_to(Square s) const;
@@ -175,7 +175,7 @@ private:
 
   // Helper functions
   void do_castle(Square kfrom, Square kto, Square rfrom, Square rto);
-  Bitboard hidden_checkers(Square ksq, Color c) const;
+  Bitboard hidden_checkers(Square ksq, Color c, Color toMove) const;
   void put_piece(Square s, Color c, PieceType pt);
   void remove_piece(Square s, Color c, PieceType pt);
   void move_piece(Square from, Square to, Color c, PieceType pt);
@@ -316,11 +316,11 @@ inline Bitboard Position::checkers() const {
 }
 
 inline Bitboard Position::discovered_check_candidates() const {
-  return hidden_checkers(king_square(~sideToMove), sideToMove);
+  return hidden_checkers(king_square(~sideToMove), sideToMove, sideToMove);
 }
 
-inline Bitboard Position::pinned_pieces() const {
-  return hidden_checkers(king_square(sideToMove), ~sideToMove);
+inline Bitboard Position::pinned_pieces(Color toMove) const {
+  return hidden_checkers(king_square(toMove), ~toMove, toMove);
 }
 
 inline bool Position::pawn_passed(Color c, Square s) const {
index 21756824b815bfa58f37f1f4f948277466dab7a8..0de9e8f9c85da4d7800ccdd32086eb831f0a0454 100644 (file)
@@ -1507,7 +1507,7 @@ void RootMove::extract_pv_from_tt(Position& pos) {
 
   } while (   tte
            && pos.pseudo_legal(m = tte->move()) // Local copy, TT could change
-           && pos.legal(m, pos.pinned_pieces())
+           && pos.legal(m, pos.pinned_pieces(pos.side_to_move()))
            && ply < MAX_PLY
            && (!pos.is_draw() || ply < 2));