summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0b944c7)
Move its content directly under StateInfo.
Verified for no speed regression.
No functional change.
if (Checks)
{
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
if (Checks)
{
if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
- && !(PseudoAttacks[Pt][from] & target & pos.check_info().checkSquares[Pt]))
+ && !(PseudoAttacks[Pt][from] & target & pos.check_squares(Pt)))
continue;
if (pos.discovered_check_candidates() & from)
continue;
if (pos.discovered_check_candidates() & from)
Bitboard b = pos.attacks_from<Pt>(from) & target;
if (Checks)
Bitboard b = pos.attacks_from<Pt>(from) & target;
if (Checks)
- b &= pos.check_info().checkSquares[Pt];
+ b &= pos.check_squares(Pt);
while (b)
*moveList++ = make_move(from, pop_lsb(&b));
while (b)
*moveList++ = make_move(from, pop_lsb(&b));
/// Position::set_check_info() sets king attacks to detect if a move gives check
/// Position::set_check_info() sets king attacks to detect if a move gives check
-void Position::set_check_info(CheckInfo* ci) const {
+void Position::set_check_info(StateInfo* si) const {
- ci->blockersForKing[WHITE] = slider_blockers(pieces(BLACK), square<KING>(WHITE));
- ci->blockersForKing[BLACK] = slider_blockers(pieces(WHITE), square<KING>(BLACK));
+ si->blockersForKing[WHITE] = slider_blockers(pieces(BLACK), square<KING>(WHITE));
+ si->blockersForKing[BLACK] = slider_blockers(pieces(WHITE), square<KING>(BLACK));
- Square ksq = ci->ksq = square<KING>(~sideToMove);
+ Square ksq = square<KING>(~sideToMove);
- ci->checkSquares[PAWN] = attacks_from<PAWN>(ksq, ~sideToMove);
- ci->checkSquares[KNIGHT] = attacks_from<KNIGHT>(ksq);
- ci->checkSquares[BISHOP] = attacks_from<BISHOP>(ksq);
- ci->checkSquares[ROOK] = attacks_from<ROOK>(ksq);
- ci->checkSquares[QUEEN] = ci->checkSquares[BISHOP] | ci->checkSquares[ROOK];
- ci->checkSquares[KING] = 0;
+ si->checkSquares[PAWN] = attacks_from<PAWN>(ksq, ~sideToMove);
+ si->checkSquares[KNIGHT] = attacks_from<KNIGHT>(ksq);
+ si->checkSquares[BISHOP] = attacks_from<BISHOP>(ksq);
+ si->checkSquares[ROOK] = attacks_from<ROOK>(ksq);
+ si->checkSquares[QUEEN] = si->checkSquares[BISHOP] | si->checkSquares[ROOK];
+ si->checkSquares[KING] = 0;
si->psq = SCORE_ZERO;
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
si->psq = SCORE_ZERO;
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
- set_check_info(&si->ci);
for (Bitboard b = pieces(); b; )
{
for (Bitboard b = pieces(); b; )
{
Square to = to_sq(m);
// Is there a direct check?
Square to = to_sq(m);
// Is there a direct check?
- if (st->ci.checkSquares[type_of(piece_on(from))] & to)
+ if (st->checkSquares[type_of(piece_on(from))] & to)
return true;
// Is there a discovered check?
if ( (discovered_check_candidates() & from)
return true;
// Is there a discovered check?
if ( (discovered_check_candidates() & from)
- && !aligned(from, to, st->ci.ksq))
+ && !aligned(from, to, square<KING>(~sideToMove)))
return true;
switch (type_of(m))
return true;
switch (type_of(m))
return false;
case PROMOTION:
return false;
case PROMOTION:
- return attacks_bb(Piece(promotion_type(m)), to, pieces() ^ from) & st->ci.ksq;
+ return attacks_bb(Piece(promotion_type(m)), to, pieces() ^ from) & square<KING>(~sideToMove);
// En passant capture with check? We have already handled the case
// of direct checks and ordinary discovered check, so the only case we
// En passant capture with check? We have already handled the case
// of direct checks and ordinary discovered check, so the only case we
Square capsq = make_square(file_of(to), rank_of(from));
Bitboard b = (pieces() ^ from ^ capsq) | to;
Square capsq = make_square(file_of(to), rank_of(from));
Bitboard b = (pieces() ^ from ^ capsq) | to;
- return (attacks_bb< ROOK>(st->ci.ksq, b) & pieces(sideToMove, QUEEN, ROOK))
- | (attacks_bb<BISHOP>(st->ci.ksq, b) & pieces(sideToMove, QUEEN, BISHOP));
+ return (attacks_bb< ROOK>(square<KING>(~sideToMove), b) & pieces(sideToMove, QUEEN, ROOK))
+ | (attacks_bb<BISHOP>(square<KING>(~sideToMove), b) & pieces(sideToMove, QUEEN, BISHOP));
Square kto = relative_square(sideToMove, rfrom > kfrom ? SQ_G1 : SQ_C1);
Square rto = relative_square(sideToMove, rfrom > kfrom ? SQ_F1 : SQ_D1);
Square kto = relative_square(sideToMove, rfrom > kfrom ? SQ_G1 : SQ_C1);
Square rto = relative_square(sideToMove, rfrom > kfrom ? SQ_F1 : SQ_D1);
- return (PseudoAttacks[ROOK][rto] & st->ci.ksq)
- && (attacks_bb<ROOK>(rto, (pieces() ^ kfrom ^ rfrom) | rto | kto) & st->ci.ksq);
+ return (PseudoAttacks[ROOK][rto] & square<KING>(~sideToMove))
+ && (attacks_bb<ROOK>(rto, (pieces() ^ kfrom ^ rfrom) | rto | kto) & square<KING>(~sideToMove));
}
default:
assert(false);
}
default:
assert(false);
sideToMove = ~sideToMove;
sideToMove = ~sideToMove;
- // Update CheckInfo
- set_check_info(&st->ci);
+ // Update king attacks used for fast check detection
+ set_check_info(st);
sideToMove = ~sideToMove;
sideToMove = ~sideToMove;
- set_check_info(&st->ci);
-/// CheckInfo struct keeps info used to detect if a move gives check
-
-struct CheckInfo {
-
- Bitboard blockersForKing[COLOR_NB];
- Bitboard checkSquares[PIECE_TYPE_NB];
- Square ksq;
-};
-
-
/// StateInfo struct stores information needed to restore a Position object to
/// its previous state when we retract a move. Whenever a move is made on the
/// board (by calling Position::do_move), a StateInfo object must be passed.
/// StateInfo struct stores information needed to restore a Position object to
/// its previous state when we retract a move. Whenever a move is made on the
/// board (by calling Position::do_move), a StateInfo object must be passed.
Bitboard checkersBB;
PieceType capturedType;
StateInfo* previous;
Bitboard checkersBB;
PieceType capturedType;
StateInfo* previous;
+ Bitboard blockersForKing[COLOR_NB];
+ Bitboard checkSquares[PIECE_TYPE_NB];
};
// In a std::deque references to elements are unaffected upon resizing
};
// In a std::deque references to elements are unaffected upon resizing
Bitboard checkers() const;
Bitboard discovered_check_candidates() const;
Bitboard pinned_pieces(Color c) const;
Bitboard checkers() const;
Bitboard discovered_check_candidates() const;
Bitboard pinned_pieces(Color c) const;
- const CheckInfo& check_info() const;
+ Bitboard check_squares(PieceType pt) const;
// Attacks to/from a given square
Bitboard attackers_to(Square s) const;
// Attacks to/from a given square
Bitboard attackers_to(Square s) const;
// Initialization helpers (used while setting up a position)
void set_castling_right(Color c, Square rfrom);
void set_state(StateInfo* si) const;
// Initialization helpers (used while setting up a position)
void set_castling_right(Color c, Square rfrom);
void set_state(StateInfo* si) const;
- void set_check_info(CheckInfo* ci) const;
+ void set_check_info(StateInfo* si) const;
// Other helpers
void put_piece(Color c, PieceType pt, Square s);
// Other helpers
void put_piece(Color c, PieceType pt, Square s);
}
inline Bitboard Position::discovered_check_candidates() const {
}
inline Bitboard Position::discovered_check_candidates() const {
- return st->ci.blockersForKing[~sideToMove] & pieces(sideToMove);
+ return st->blockersForKing[~sideToMove] & pieces(sideToMove);
}
inline Bitboard Position::pinned_pieces(Color c) const {
}
inline Bitboard Position::pinned_pieces(Color c) const {
- return st->ci.blockersForKing[c] & pieces(c);
+ return st->blockersForKing[c] & pieces(c);
-inline const CheckInfo& Position::check_info() const {
- return st->ci;
+inline Bitboard Position::check_squares(PieceType pt) const {
+ return st->checkSquares[pt];
}
inline bool Position::pawn_passed(Color c, Square s) const {
}
inline bool Position::pawn_passed(Color c, Square s) const {
moved_piece = pos.moved_piece(move);
givesCheck = type_of(move) == NORMAL && !pos.discovered_check_candidates()
moved_piece = pos.moved_piece(move);
givesCheck = type_of(move) == NORMAL && !pos.discovered_check_candidates()
- ? pos.check_info().checkSquares[type_of(pos.piece_on(from_sq(move)))] & to_sq(move)
+ ? pos.check_squares(type_of(pos.piece_on(from_sq(move)))) & to_sq(move)
: pos.gives_check(move);
moveCountPruning = depth < 16 * ONE_PLY
: pos.gives_check(move);
moveCountPruning = depth < 16 * ONE_PLY
assert(is_ok(move));
givesCheck = type_of(move) == NORMAL && !pos.discovered_check_candidates()
assert(is_ok(move));
givesCheck = type_of(move) == NORMAL && !pos.discovered_check_candidates()
- ? pos.check_info().checkSquares[type_of(pos.piece_on(from_sq(move)))] & to_sq(move)
+ ? pos.check_squares(type_of(pos.piece_on(from_sq(move)))) & to_sq(move)
: pos.gives_check(move);
// Futility pruning
: pos.gives_check(move);
// Futility pruning