1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 09:39:36 +00:00

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
This commit is contained in:
Gary Linscott 2013-11-07 13:59:11 -05:00 committed by Marco Costalba
parent ecd07e51d0
commit 13d1f0ae43
6 changed files with 19 additions and 12 deletions

View file

@ -83,6 +83,8 @@ namespace {
// king is on g8 and there's a white knight on g5, this knight adds // king is on g8 and there's a white knight on g5, this knight adds
// 2 to kingAdjacentZoneAttacksCount[BLACK]. // 2 to kingAdjacentZoneAttacksCount[BLACK].
int kingAdjacentZoneAttacksCount[COLOR_NB]; int kingAdjacentZoneAttacksCount[COLOR_NB];
Bitboard pinnedPieces[COLOR_NB];
}; };
// Evaluation grain size, must be a power of 2 // 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 Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Down = (Us == WHITE ? DELTA_S : DELTA_N); 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)); Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from<KING>(pos.king_square(Them));
ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us); 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)) : Piece == ROOK ? attacks_bb< ROOK>(s, pos.pieces() ^ pos.pieces(Us, ROOK, QUEEN))
: pos.attacks_from<Piece>(s); : pos.attacks_from<Piece>(s);
if (ei.pinnedPieces[Us] & s)
b &= PseudoAttacks[QUEEN][pos.king_square(Us)];
ei.attackedBy[Us][Piece] |= b; ei.attackedBy[Us][Piece] |= b;
if (b & ei.kingRing[Them]) if (b & ei.kingRing[Them])

View file

@ -407,7 +407,7 @@ template<>
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* mlist) { ExtMove* generate<LEGAL>(const Position& pos, ExtMove* mlist) {
ExtMove *end, *cur = 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()); Square ksq = pos.king_square(pos.side_to_move());
end = pos.checkers() ? generate<EVASIONS>(pos, mlist) end = pos.checkers() ? generate<EVASIONS>(pos, mlist)

View file

@ -133,7 +133,7 @@ const string move_to_san(Position& pos, Move m) {
while (b) while (b)
{ {
Move move = make_move(pop_lsb(&b), to); 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); others ^= from_sq(move);
} }

View file

@ -98,7 +98,7 @@ CheckInfo::CheckInfo(const Position& pos) {
Color them = ~pos.side_to_move(); Color them = ~pos.side_to_move();
ksq = pos.king_square(them); ksq = pos.king_square(them);
pinned = pos.pinned_pieces(); pinned = pos.pinned_pieces(pos.side_to_move());
dcCandidates = pos.discovered_check_candidates(); dcCandidates = pos.discovered_check_candidates();
checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them); 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, /// pieces, according to the call parameters. Pinned pieces protect our king,
/// discovery check pieces attack the enemy 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; 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(); b = between_bb(ksq, pop_lsb(&pinners)) & pieces();
if (!more_than_one(b)) if (!more_than_one(b))
result |= b & pieces(sideToMove); result |= b & pieces(toMove);
} }
return result; return result;
} }
@ -477,7 +477,7 @@ Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) {
bool Position::legal(Move m, Bitboard pinned) const { bool Position::legal(Move m, Bitboard pinned) const {
assert(is_ok(m)); assert(is_ok(m));
assert(pinned == pinned_pieces()); assert(pinned == pinned_pieces(pos.side_to_move()));
Color us = sideToMove; Color us = sideToMove;
Square from = from_sq(m); Square from = from_sq(m);

View file

@ -108,7 +108,7 @@ public:
// Checking // Checking
Bitboard checkers() const; Bitboard checkers() const;
Bitboard discovered_check_candidates() const; Bitboard discovered_check_candidates() const;
Bitboard pinned_pieces() const; Bitboard pinned_pieces(Color toMove) const;
// Attacks to/from a given square // Attacks to/from a given square
Bitboard attackers_to(Square s) const; Bitboard attackers_to(Square s) const;
@ -175,7 +175,7 @@ private:
// Helper functions // Helper functions
void do_castle(Square kfrom, Square kto, Square rfrom, Square rto); 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 put_piece(Square s, Color c, PieceType pt);
void remove_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); 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 { 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 { inline Bitboard Position::pinned_pieces(Color toMove) const {
return hidden_checkers(king_square(sideToMove), ~sideToMove); return hidden_checkers(king_square(toMove), ~toMove, toMove);
} }
inline bool Position::pawn_passed(Color c, Square s) const { inline bool Position::pawn_passed(Color c, Square s) const {

View file

@ -1507,7 +1507,7 @@ void RootMove::extract_pv_from_tt(Position& pos) {
} while ( tte } while ( tte
&& pos.pseudo_legal(m = tte->move()) // Local copy, TT could change && 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 && ply < MAX_PLY
&& (!pos.is_draw() || ply < 2)); && (!pos.is_draw() || ply < 2));