From 018022b8666200dacd3533e215e2de41f93df9da Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Mon, 20 Jun 2011 09:46:31 +0200 Subject: [PATCH] Use CheckInfo to store pinned bitboard This trivial change gives an impressive 2,5% speedup !!!! Also retire one unused move_gives_check() overload. No functional change. Signed-off-by: Marco Costalba --- src/position.cpp | 14 +++++--------- src/position.h | 2 +- src/search.cpp | 17 +++++++---------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index adeef6ec..99445acd 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -90,13 +90,14 @@ CheckInfo::CheckInfo(const Position& pos) { ksq = pos.king_square(them); dcCandidates = pos.discovered_check_candidates(us); + pinned = pos.pinned_pieces(us); - checkSq[PAWN] = pos.attacks_from(ksq, them); + checkSq[PAWN] = pos.attacks_from(ksq, them); checkSq[KNIGHT] = pos.attacks_from(ksq); checkSq[BISHOP] = pos.attacks_from(ksq); - checkSq[ROOK] = pos.attacks_from(ksq); - checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK]; - checkSq[KING] = EmptyBoardBB; + checkSq[ROOK] = pos.attacks_from(ksq); + checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK]; + checkSq[KING] = EmptyBoardBB; } @@ -746,11 +747,6 @@ bool Position::move_is_pl(const Move m) const { /// Position::move_gives_check() tests whether a pseudo-legal move is a check -bool Position::move_gives_check(Move m) const { - - return move_gives_check(m, CheckInfo(*this)); -} - bool Position::move_gives_check(Move m, const CheckInfo& ci) const { assert(is_ok()); diff --git a/src/position.h b/src/position.h index 6307f126..06ef6ab1 100644 --- a/src/position.h +++ b/src/position.h @@ -41,6 +41,7 @@ struct CheckInfo { explicit CheckInfo(const Position&); Bitboard dcCandidates; + Bitboard pinned; Bitboard checkSq[8]; Square ksq; }; @@ -187,7 +188,6 @@ public: // Properties of moves bool pl_move_is_legal(Move m, Bitboard pinned) const; bool move_is_pl(const Move m) const; - bool move_gives_check(Move m) const; bool move_gives_check(Move m, const CheckInfo& ci) const; bool move_is_capture(Move m) const; bool move_is_passed_pawn_push(Move m) const; diff --git a/src/search.cpp b/src/search.cpp index ea9fc554..2e12f82e 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -717,7 +717,6 @@ namespace { StateInfo st; const TTEntry *tte; Key posKey; - Bitboard pinned; Move ttMove, move, excludedMove, threatMove; Depth ext, newDepth; ValueType vt; @@ -918,12 +917,12 @@ namespace { assert(rdepth >= ONE_PLY); MovePicker mp(pos, ttMove, H, Position::see_value(pos.captured_piece_type())); - pinned = pos.pinned_pieces(pos.side_to_move()); + CheckInfo ci(pos); while ((move = mp.get_next_move()) != MOVE_NONE) - if (pos.pl_move_is_legal(move, pinned)) + if (pos.pl_move_is_legal(move, ci.pinned)) { - pos.do_move(move, st); + pos.do_move(move, st, ci, pos.move_gives_check(move, ci)); value = -search(pos, ss+1, -rbeta, -rbeta+1, rdepth); pos.undo_move(move); if (value >= rbeta) @@ -951,7 +950,6 @@ split_point_start: // At split points actual search starts from here // Initialize a MovePicker object for the current position MovePickerExt mp(pos, ttMove, depth, H, ss, PvNode ? -VALUE_INFINITE : beta); CheckInfo ci(pos); - pinned = pos.pinned_pieces(pos.side_to_move()); ss->bestMove = MOVE_NONE; futilityBase = ss->eval + ss->evalMargin; singularExtensionNode = !RootNode @@ -979,7 +977,7 @@ split_point_start: // At split points actual search starts from here continue; // At PV and SpNode nodes we want the moves to be legal - if ((PvNode || SpNode) && !pos.pl_move_is_legal(move, pinned)) + if ((PvNode || SpNode) && !pos.pl_move_is_legal(move, ci.pinned)) continue; if (SpNode) @@ -1026,7 +1024,7 @@ split_point_start: // At split points actual search starts from here // a margin then we extend ttMove. if ( singularExtensionNode && move == ttMove - && pos.pl_move_is_legal(move, pinned) + && pos.pl_move_is_legal(move, ci.pinned) && ext < ONE_PLY) { Value ttValue = value_from_tt(tte->value(), ss->ply); @@ -1101,7 +1099,7 @@ split_point_start: // At split points actual search starts from here } // Check for legality only before to do the move - if (!pos.pl_move_is_legal(move, pinned)) + if (!pos.pl_move_is_legal(move, ci.pinned)) { moveCount--; continue; @@ -1395,7 +1393,6 @@ split_point_start: // At split points actual search starts from here // be generated. MovePicker mp(pos, ttMove, depth, H, move_to((ss-1)->currentMove)); CheckInfo ci(pos); - Bitboard pinned = pos.pinned_pieces(pos.side_to_move()); // Loop through the moves until no moves remain or a beta cutoff occurs while ( alpha < beta @@ -1464,7 +1461,7 @@ split_point_start: // At split points actual search starts from here } // Check for legality only before to do the move - if (!pos.pl_move_is_legal(move, pinned)) + if (!pos.pl_move_is_legal(move, ci.pinned)) continue; // Update current move -- 2.39.2