From 13d1f0ae4301b86c610a58332c3c19d9101704da Mon Sep 17 00:00:00 2001 From: Gary Linscott Date: Thu, 7 Nov 2013 13:59:11 -0500 Subject: [PATCH] Restrict mobility of pinned pieces 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 | 7 +++++++ src/movegen.cpp | 2 +- src/notation.cpp | 2 +- src/position.cpp | 8 ++++---- src/position.h | 10 +++++----- src/search.cpp | 2 +- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 5b1f4f40..27980238 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -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(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(s); + if (ei.pinnedPieces[Us] & s) + b &= PseudoAttacks[QUEEN][pos.king_square(Us)]; + ei.attackedBy[Us][Piece] |= b; if (b & ei.kingRing[Them]) diff --git a/src/movegen.cpp b/src/movegen.cpp index 96dd89c5..1524bf1f 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -407,7 +407,7 @@ template<> ExtMove* generate(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(pos, mlist) diff --git a/src/notation.cpp b/src/notation.cpp index 3f79a44b..d017c079 100644 --- a/src/notation.cpp +++ b/src/notation.cpp @@ -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); } diff --git a/src/position.cpp b/src/position.cpp index fade3cba..ec008338 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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(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); diff --git a/src/position.h b/src/position.h index e73c8ff5..c333e55a 100644 --- a/src/position.h +++ b/src/position.h @@ -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 { diff --git a/src/search.cpp b/src/search.cpp index 21756824..0de9e8f9 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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)); -- 2.39.2