mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +00:00
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 <mcostalba@gmail.com>
This commit is contained in:
parent
7ea38e980b
commit
018022b866
3 changed files with 13 additions and 20 deletions
|
@ -90,13 +90,14 @@ CheckInfo::CheckInfo(const Position& pos) {
|
||||||
|
|
||||||
ksq = pos.king_square(them);
|
ksq = pos.king_square(them);
|
||||||
dcCandidates = pos.discovered_check_candidates(us);
|
dcCandidates = pos.discovered_check_candidates(us);
|
||||||
|
pinned = pos.pinned_pieces(us);
|
||||||
|
|
||||||
checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them);
|
checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them);
|
||||||
checkSq[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
|
checkSq[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
|
||||||
checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
|
checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
|
||||||
checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
|
checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
|
||||||
checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
|
checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
|
||||||
checkSq[KING] = EmptyBoardBB;
|
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
|
/// 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 {
|
bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
||||||
|
|
||||||
assert(is_ok());
|
assert(is_ok());
|
||||||
|
|
|
@ -41,6 +41,7 @@ struct CheckInfo {
|
||||||
explicit CheckInfo(const Position&);
|
explicit CheckInfo(const Position&);
|
||||||
|
|
||||||
Bitboard dcCandidates;
|
Bitboard dcCandidates;
|
||||||
|
Bitboard pinned;
|
||||||
Bitboard checkSq[8];
|
Bitboard checkSq[8];
|
||||||
Square ksq;
|
Square ksq;
|
||||||
};
|
};
|
||||||
|
@ -187,7 +188,6 @@ public:
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
||||||
bool move_is_pl(const Move m) 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_gives_check(Move m, const CheckInfo& ci) const;
|
||||||
bool move_is_capture(Move m) const;
|
bool move_is_capture(Move m) const;
|
||||||
bool move_is_passed_pawn_push(Move m) const;
|
bool move_is_passed_pawn_push(Move m) const;
|
||||||
|
|
|
@ -717,7 +717,6 @@ namespace {
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
const TTEntry *tte;
|
const TTEntry *tte;
|
||||||
Key posKey;
|
Key posKey;
|
||||||
Bitboard pinned;
|
|
||||||
Move ttMove, move, excludedMove, threatMove;
|
Move ttMove, move, excludedMove, threatMove;
|
||||||
Depth ext, newDepth;
|
Depth ext, newDepth;
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
|
@ -918,12 +917,12 @@ namespace {
|
||||||
assert(rdepth >= ONE_PLY);
|
assert(rdepth >= ONE_PLY);
|
||||||
|
|
||||||
MovePicker mp(pos, ttMove, H, Position::see_value(pos.captured_piece_type()));
|
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)
|
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<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth);
|
value = -search<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth);
|
||||||
pos.undo_move(move);
|
pos.undo_move(move);
|
||||||
if (value >= rbeta)
|
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
|
// Initialize a MovePicker object for the current position
|
||||||
MovePickerExt<NT> mp(pos, ttMove, depth, H, ss, PvNode ? -VALUE_INFINITE : beta);
|
MovePickerExt<NT> mp(pos, ttMove, depth, H, ss, PvNode ? -VALUE_INFINITE : beta);
|
||||||
CheckInfo ci(pos);
|
CheckInfo ci(pos);
|
||||||
pinned = pos.pinned_pieces(pos.side_to_move());
|
|
||||||
ss->bestMove = MOVE_NONE;
|
ss->bestMove = MOVE_NONE;
|
||||||
futilityBase = ss->eval + ss->evalMargin;
|
futilityBase = ss->eval + ss->evalMargin;
|
||||||
singularExtensionNode = !RootNode
|
singularExtensionNode = !RootNode
|
||||||
|
@ -979,7 +977,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// At PV and SpNode nodes we want the moves to be legal
|
// 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;
|
continue;
|
||||||
|
|
||||||
if (SpNode)
|
if (SpNode)
|
||||||
|
@ -1026,7 +1024,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
// a margin then we extend ttMove.
|
// a margin then we extend ttMove.
|
||||||
if ( singularExtensionNode
|
if ( singularExtensionNode
|
||||||
&& move == ttMove
|
&& move == ttMove
|
||||||
&& pos.pl_move_is_legal(move, pinned)
|
&& pos.pl_move_is_legal(move, ci.pinned)
|
||||||
&& ext < ONE_PLY)
|
&& ext < ONE_PLY)
|
||||||
{
|
{
|
||||||
Value ttValue = value_from_tt(tte->value(), ss->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
|
// 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--;
|
moveCount--;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1395,7 +1393,6 @@ split_point_start: // At split points actual search starts from here
|
||||||
// be generated.
|
// be generated.
|
||||||
MovePicker mp(pos, ttMove, depth, H, move_to((ss-1)->currentMove));
|
MovePicker mp(pos, ttMove, depth, H, move_to((ss-1)->currentMove));
|
||||||
CheckInfo ci(pos);
|
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
|
// Loop through the moves until no moves remain or a beta cutoff occurs
|
||||||
while ( alpha < beta
|
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
|
// 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;
|
continue;
|
||||||
|
|
||||||
// Update current move
|
// Update current move
|
||||||
|
|
Loading…
Add table
Reference in a new issue