Cache pinned and discovery check bitboards

After have been calculated cache their values
so to avoid another expensive call to hidden_checks()
if pinned_pieces() or discovered_check_candidates() are
called with the same position.

Add also interface to get pinners bitboard, we already have
this value so save it instead of discard.

Now that, after the first call to pinned_pieces() the following
are very cheap we can rewrite and cleanup all the checking handling.

So this patch is a prerequisite for future work.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2009-02-19 16:28:35 +01:00
parent 7f4f18f959
commit 5f142ec209
2 changed files with 60 additions and 21 deletions

View File

@@ -82,7 +82,7 @@ enum CastleRights {
struct UndoInfo {
int castleRights;
Square epSquare;
Bitboard checkersBB;
Bitboard checkersBB, pinners[2], pinned[2], dcCandidates[2];
Key key, pawnKey, materialKey;
int rule50;
Move lastMove;
@@ -197,6 +197,7 @@ public:
// Bitboards for pinned pieces and discovered check candidates
Bitboard discovered_check_candidates(Color c) const;
Bitboard pinned_pieces(Color c, Bitboard& p) const;
Bitboard pinned_pieces(Color c) const;
// Checking pieces
@@ -312,7 +313,7 @@ private:
void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
template<PieceType Piece, bool FindPinned>
Bitboard hidden_checks(Color c, Square ksq) const;
Bitboard hidden_checks(Color c, Square ksq, Bitboard& pinners) const;
// Computing hash keys from scratch (for initialization and debugging)
Key compute_key() const;
@@ -329,6 +330,7 @@ private:
// Bitboards
Bitboard byColorBB[2], byTypeBB[8];
Bitboard checkersBB;
mutable Bitboard pinners[2], pinned[2], dcCandidates[2];
// Board
Piece board[64];