mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 09:39:36 +00:00
Remove update_checkers()
Now that we have CheckInfo we don't need it anymore. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
ad44ff2bca
commit
bf395c6be1
3 changed files with 29 additions and 62 deletions
|
@ -343,16 +343,15 @@ void Position::copy(const Position& pos) {
|
||||||
template<bool FindPinned>
|
template<bool FindPinned>
|
||||||
Bitboard Position::hidden_checkers(Color c) const {
|
Bitboard Position::hidden_checkers(Color c) const {
|
||||||
|
|
||||||
Bitboard pinners, result = EmptyBoardBB;
|
Bitboard result = EmptyBoardBB;
|
||||||
|
Bitboard pinners = pieces_of_color(FindPinned ? opposite_color(c) : c);
|
||||||
|
|
||||||
// Pinned pieces protect our king, dicovery checks attack
|
// Pinned pieces protect our king, dicovery checks attack
|
||||||
// the enemy king.
|
// the enemy king.
|
||||||
Square ksq = king_square(FindPinned ? c : opposite_color(c));
|
Square ksq = king_square(FindPinned ? c : opposite_color(c));
|
||||||
|
|
||||||
// Pinners are sliders, not checkers, that give check when
|
// Pinners are sliders, not checkers, that give check when candidate pinned is removed
|
||||||
// candidate pinned is removed.
|
pinners &= (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq]) | (pieces(BISHOP, QUEEN) & BishopPseudoAttacks[ksq]);
|
||||||
pinners = (pieces(ROOK, QUEEN, FindPinned ? opposite_color(c) : c) & RookPseudoAttacks[ksq])
|
|
||||||
| (pieces(BISHOP, QUEEN, FindPinned ? opposite_color(c) : c) & BishopPseudoAttacks[ksq]);
|
|
||||||
|
|
||||||
if (FindPinned && pinners)
|
if (FindPinned && pinners)
|
||||||
pinners &= ~st->checkersBB;
|
pinners &= ~st->checkersBB;
|
||||||
|
@ -647,49 +646,17 @@ bool Position::move_is_check(Move m, const CheckInfo& ci) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::update_checkers() udpates chekers info given the move. It is called
|
|
||||||
/// in do_move() and is faster then find_checkers().
|
|
||||||
|
|
||||||
template<PieceType Piece>
|
|
||||||
inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square from,
|
|
||||||
Square to, Bitboard dcCandidates) {
|
|
||||||
|
|
||||||
const bool Bishop = (Piece == QUEEN || Piece == BISHOP);
|
|
||||||
const bool Rook = (Piece == QUEEN || Piece == ROOK);
|
|
||||||
const bool Slider = Bishop || Rook;
|
|
||||||
|
|
||||||
assert(*pCheckersBB == EmptyBoardBB);
|
|
||||||
|
|
||||||
// Direct checks
|
|
||||||
if ( ( !Slider // try to early skip slide piece attacks
|
|
||||||
|| (Bishop && bit_is_set(BishopPseudoAttacks[ksq], to))
|
|
||||||
|| (Rook && bit_is_set(RookPseudoAttacks[ksq], to)))
|
|
||||||
&& bit_is_set(Piece == PAWN ? attacks_from<PAWN>(ksq, opposite_color(sideToMove)) : attacks_from<Piece>(ksq) , to))
|
|
||||||
{
|
|
||||||
*pCheckersBB = SetMaskBB[to];
|
|
||||||
}
|
|
||||||
// Discovery checks
|
|
||||||
if (Piece != QUEEN && dcCandidates && bit_is_set(dcCandidates, from))
|
|
||||||
{
|
|
||||||
if (Piece != ROOK)
|
|
||||||
(*pCheckersBB) |= (attacks_from<ROOK>(ksq) & pieces(ROOK, QUEEN, side_to_move()));
|
|
||||||
|
|
||||||
if (Piece != BISHOP)
|
|
||||||
(*pCheckersBB) |= (attacks_from<BISHOP>(ksq) & pieces(BISHOP, QUEEN, side_to_move()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Position::do_move() makes a move, and saves all information necessary
|
/// Position::do_move() makes a move, and saves all information necessary
|
||||||
/// to a StateInfo object. The move is assumed to be legal.
|
/// to a StateInfo object. The move is assumed to be legal.
|
||||||
/// Pseudo-legal moves should be filtered out before this function is called.
|
/// Pseudo-legal moves should be filtered out before this function is called.
|
||||||
|
|
||||||
void Position::do_move(Move m, StateInfo& newSt) {
|
void Position::do_move(Move m, StateInfo& newSt) {
|
||||||
|
|
||||||
do_move(m, newSt, discovered_check_candidates(side_to_move()));
|
CheckInfo ci(*this);
|
||||||
|
do_move(m, newSt, ci, move_is_check(m, ci));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates, bool moveCanBeCheck) {
|
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
|
||||||
|
|
||||||
assert(is_ok());
|
assert(is_ok());
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
|
@ -860,22 +827,24 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates, bool mov
|
||||||
// Update checkers bitboard, piece must be already moved
|
// Update checkers bitboard, piece must be already moved
|
||||||
st->checkersBB = EmptyBoardBB;
|
st->checkersBB = EmptyBoardBB;
|
||||||
|
|
||||||
if (moveCanBeCheck)
|
if (moveIsCheck)
|
||||||
{
|
{
|
||||||
if (ep | pm)
|
if (ep | pm)
|
||||||
st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us);
|
st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Square ksq = king_square(them);
|
// Direct checks
|
||||||
switch (pt)
|
if (bit_is_set(ci.checkSq[pt], to))
|
||||||
|
st->checkersBB = SetMaskBB[to];
|
||||||
|
|
||||||
|
// Discovery checks
|
||||||
|
if (ci.dcCandidates && bit_is_set(ci.dcCandidates, from))
|
||||||
{
|
{
|
||||||
case PAWN: update_checkers<PAWN>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
|
if (pt != ROOK)
|
||||||
case KNIGHT: update_checkers<KNIGHT>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
|
st->checkersBB |= (attacks_from<ROOK>(ci.ksq) & pieces(ROOK, QUEEN, us));
|
||||||
case BISHOP: update_checkers<BISHOP>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
|
|
||||||
case ROOK: update_checkers<ROOK>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
|
if (pt != BISHOP)
|
||||||
case QUEEN: update_checkers<QUEEN>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
|
st->checkersBB |= (attacks_from<BISHOP>(ci.ksq) & pieces(BISHOP, QUEEN, us));
|
||||||
case KING: update_checkers<KING>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
|
|
||||||
default: assert(false); break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,7 +236,7 @@ public:
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void saveState();
|
void saveState();
|
||||||
void do_move(Move m, StateInfo& st);
|
void do_move(Move m, StateInfo& st);
|
||||||
void do_move(Move m, StateInfo& st, Bitboard dcCandidates, bool moveCanBeCheck = true);
|
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
void do_null_move(StateInfo& st);
|
void do_null_move(StateInfo& st);
|
||||||
void undo_null_move();
|
void undo_null_move();
|
||||||
|
@ -296,9 +296,6 @@ private:
|
||||||
void undo_castle_move(Move m);
|
void undo_castle_move(Move m);
|
||||||
void find_checkers();
|
void find_checkers();
|
||||||
|
|
||||||
template<PieceType Piece>
|
|
||||||
void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
|
|
||||||
|
|
||||||
template<bool FindPinned>
|
template<bool FindPinned>
|
||||||
Bitboard hidden_checkers(Color c) const;
|
Bitboard hidden_checkers(Color c) const;
|
||||||
|
|
||||||
|
|
|
@ -349,7 +349,7 @@ int perft(Position& pos, Depth depth)
|
||||||
while ((move = mp.get_next_move()) != MOVE_NONE)
|
while ((move = mp.get_next_move()) != MOVE_NONE)
|
||||||
{
|
{
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
pos.do_move(move, st, ci.dcCandidates, pos.move_is_check(move, ci));
|
pos.do_move(move, st, ci, pos.move_is_check(move, ci));
|
||||||
sum += perft(pos, depth - OnePly);
|
sum += perft(pos, depth - OnePly);
|
||||||
pos.undo_move(move);
|
pos.undo_move(move);
|
||||||
}
|
}
|
||||||
|
@ -898,13 +898,14 @@ namespace {
|
||||||
<< " currmovenumber " << i + 1 << std::endl;
|
<< " currmovenumber " << i + 1 << std::endl;
|
||||||
|
|
||||||
// Decide search depth for this move
|
// Decide search depth for this move
|
||||||
|
bool moveIsCheck = pos.move_is_check(move);
|
||||||
bool captureOrPromotion = pos.move_is_capture_or_promotion(move);
|
bool captureOrPromotion = pos.move_is_capture_or_promotion(move);
|
||||||
bool dangerous;
|
bool dangerous;
|
||||||
ext = extension(pos, move, true, captureOrPromotion, pos.move_is_check(move), false, false, &dangerous);
|
ext = extension(pos, move, true, captureOrPromotion, moveIsCheck, false, false, &dangerous);
|
||||||
newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
|
newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
|
||||||
|
|
||||||
// Make the move, and search it
|
// Make the move, and search it
|
||||||
pos.do_move(move, st, ci.dcCandidates);
|
pos.do_move(move, st, ci, moveIsCheck);
|
||||||
|
|
||||||
if (i < MultiPV)
|
if (i < MultiPV)
|
||||||
{
|
{
|
||||||
|
@ -1135,7 +1136,7 @@ namespace {
|
||||||
newDepth = depth - OnePly + ext;
|
newDepth = depth - OnePly + ext;
|
||||||
|
|
||||||
// Make and search the move
|
// Make and search the move
|
||||||
pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
|
pos.do_move(move, st, ci, moveIsCheck);
|
||||||
|
|
||||||
if (moveCount == 1) // The first move in list is the PV
|
if (moveCount == 1) // The first move in list is the PV
|
||||||
value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID);
|
value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID);
|
||||||
|
@ -1424,7 +1425,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make and search the move
|
// Make and search the move
|
||||||
pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
|
pos.do_move(move, st, ci, moveIsCheck);
|
||||||
|
|
||||||
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
||||||
// if the move fails high will be re-searched at full depth.
|
// if the move fails high will be re-searched at full depth.
|
||||||
|
@ -1637,7 +1638,7 @@ namespace {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Make and search the move
|
// Make and search the move
|
||||||
pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
|
pos.do_move(move, st, ci, moveIsCheck);
|
||||||
value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID);
|
value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID);
|
||||||
pos.undo_move(move);
|
pos.undo_move(move);
|
||||||
|
|
||||||
|
@ -1764,7 +1765,7 @@ namespace {
|
||||||
|
|
||||||
// Make and search the move.
|
// Make and search the move.
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
pos.do_move(move, st, sp->dcCandidates, moveIsCheck);
|
pos.do_move(move, st, ci, moveIsCheck);
|
||||||
|
|
||||||
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
||||||
// if the move fails high will be re-searched at full depth.
|
// if the move fails high will be re-searched at full depth.
|
||||||
|
@ -1870,7 +1871,7 @@ namespace {
|
||||||
|
|
||||||
// Make and search the move.
|
// Make and search the move.
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
pos.do_move(move, st, sp->dcCandidates, moveIsCheck);
|
pos.do_move(move, st, ci, moveIsCheck);
|
||||||
|
|
||||||
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
||||||
// if the move fails high will be re-searched at full depth.
|
// if the move fails high will be re-searched at full depth.
|
||||||
|
|
Loading…
Add table
Reference in a new issue