mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-17 19:22:18 +01:00
DroidFish: Updated stockfish engine to git version from 2016-08-28.
This commit is contained in:
@@ -81,25 +81,6 @@ PieceType min_attacker<KING>(const Bitboard*, Square, Bitboard, Bitboard&, Bitbo
|
||||
} // namespace
|
||||
|
||||
|
||||
/// CheckInfo constructor
|
||||
|
||||
CheckInfo::CheckInfo(const Position& pos) {
|
||||
|
||||
Color them = ~pos.side_to_move();
|
||||
ksq = pos.square<KING>(them);
|
||||
|
||||
pinned = pos.pinned_pieces(pos.side_to_move());
|
||||
dcCandidates = pos.discovered_check_candidates();
|
||||
|
||||
checkSquares[PAWN] = pos.attacks_from<PAWN>(ksq, them);
|
||||
checkSquares[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
|
||||
checkSquares[BISHOP] = pos.attacks_from<BISHOP>(ksq);
|
||||
checkSquares[ROOK] = pos.attacks_from<ROOK>(ksq);
|
||||
checkSquares[QUEEN] = checkSquares[BISHOP] | checkSquares[ROOK];
|
||||
checkSquares[KING] = 0;
|
||||
}
|
||||
|
||||
|
||||
/// operator<<(Position) returns an ASCII representation of the position
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Position& pos) {
|
||||
@@ -311,6 +292,24 @@ void Position::set_castling_right(Color c, Square rfrom) {
|
||||
}
|
||||
|
||||
|
||||
/// Position::set_check_info() sets king attacks to detect if a move gives check
|
||||
|
||||
void Position::set_check_info(StateInfo* si) const {
|
||||
|
||||
si->blockersForKing[WHITE] = slider_blockers(pieces(BLACK), square<KING>(WHITE));
|
||||
si->blockersForKing[BLACK] = slider_blockers(pieces(WHITE), square<KING>(BLACK));
|
||||
|
||||
Square ksq = square<KING>(~sideToMove);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/// Position::set_state() computes the hash keys of the position, and other
|
||||
/// data that once computed is updated incrementally as moves are made.
|
||||
/// The function is only used when a new position is set up, and to verify
|
||||
@@ -321,9 +320,10 @@ void Position::set_state(StateInfo* si) const {
|
||||
si->key = si->pawnKey = si->materialKey = 0;
|
||||
si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO;
|
||||
si->psq = SCORE_ZERO;
|
||||
|
||||
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
|
||||
|
||||
set_check_info(si);
|
||||
|
||||
for (Bitboard b = pieces(); b; )
|
||||
{
|
||||
Square s = pop_lsb(&b);
|
||||
@@ -420,14 +420,14 @@ Phase Position::game_phase() const {
|
||||
}
|
||||
|
||||
|
||||
/// Position::slider_blockers() returns a bitboard of all the pieces in 'target' that
|
||||
/// Position::slider_blockers() returns a bitboard of all the pieces (both colors) that
|
||||
/// are blocking attacks on the square 's' from 'sliders'. A piece blocks a slider
|
||||
/// if removing that piece from the board would result in a position where square 's'
|
||||
/// is attacked. For example, a king-attack blocking piece can be either a pinned or
|
||||
/// a discovered check piece, according if its color is the opposite or the same of
|
||||
/// the color of the slider.
|
||||
|
||||
Bitboard Position::slider_blockers(Bitboard target, Bitboard sliders, Square s) const {
|
||||
Bitboard Position::slider_blockers(Bitboard sliders, Square s) const {
|
||||
|
||||
Bitboard b, pinners, result = 0;
|
||||
|
||||
@@ -440,7 +440,7 @@ Bitboard Position::slider_blockers(Bitboard target, Bitboard sliders, Square s)
|
||||
b = between_bb(s, pop_lsb(&pinners)) & pieces();
|
||||
|
||||
if (!more_than_one(b))
|
||||
result |= b & target;
|
||||
result |= b;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -462,10 +462,9 @@ Bitboard Position::attackers_to(Square s, Bitboard occupied) const {
|
||||
|
||||
/// Position::legal() tests whether a pseudo-legal move is legal
|
||||
|
||||
bool Position::legal(Move m, Bitboard pinned) const {
|
||||
bool Position::legal(Move m) const {
|
||||
|
||||
assert(is_ok(m));
|
||||
assert(pinned == pinned_pieces(sideToMove));
|
||||
|
||||
Color us = sideToMove;
|
||||
Square from = from_sq(m);
|
||||
@@ -500,7 +499,7 @@ bool Position::legal(Move m, Bitboard pinned) const {
|
||||
|
||||
// A non-king move is legal if and only if it is not pinned or it
|
||||
// is moving along the ray towards or away from the king.
|
||||
return !(pinned & from)
|
||||
return !(pinned_pieces(us) & from)
|
||||
|| aligned(from, to_sq(m), square<KING>(us));
|
||||
}
|
||||
|
||||
@@ -579,22 +578,21 @@ bool Position::pseudo_legal(const Move m) const {
|
||||
|
||||
/// Position::gives_check() tests whether a pseudo-legal move gives a check
|
||||
|
||||
bool Position::gives_check(Move m, const CheckInfo& ci) const {
|
||||
bool Position::gives_check(Move m) const {
|
||||
|
||||
assert(is_ok(m));
|
||||
assert(ci.dcCandidates == discovered_check_candidates());
|
||||
assert(color_of(moved_piece(m)) == sideToMove);
|
||||
|
||||
Square from = from_sq(m);
|
||||
Square to = to_sq(m);
|
||||
|
||||
// Is there a direct check?
|
||||
if (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 ( (ci.dcCandidates & from)
|
||||
&& !aligned(from, to, ci.ksq))
|
||||
if ( (discovered_check_candidates() & from)
|
||||
&& !aligned(from, to, square<KING>(~sideToMove)))
|
||||
return true;
|
||||
|
||||
switch (type_of(m))
|
||||
@@ -603,7 +601,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
|
||||
return false;
|
||||
|
||||
case PROMOTION:
|
||||
return attacks_bb(Piece(promotion_type(m)), to, pieces() ^ from) & 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
|
||||
@@ -614,8 +612,8 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
|
||||
Square capsq = make_square(file_of(to), rank_of(from));
|
||||
Bitboard b = (pieces() ^ from ^ capsq) | to;
|
||||
|
||||
return (attacks_bb< ROOK>(ci.ksq, b) & pieces(sideToMove, QUEEN, ROOK))
|
||||
| (attacks_bb<BISHOP>(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));
|
||||
}
|
||||
case CASTLING:
|
||||
{
|
||||
@@ -624,8 +622,8 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
|
||||
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] & ci.ksq)
|
||||
&& (attacks_bb<ROOK>(rto, (pieces() ^ kfrom ^ rfrom) | rto | kto) & ci.ksq);
|
||||
return (PseudoAttacks[ROOK][rto] & square<KING>(~sideToMove))
|
||||
&& (attacks_bb<ROOK>(rto, (pieces() ^ kfrom ^ rfrom) | rto | kto) & square<KING>(~sideToMove));
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
@@ -801,6 +799,9 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
||||
|
||||
sideToMove = ~sideToMove;
|
||||
|
||||
// Update king attacks used for fast check detection
|
||||
set_check_info(st);
|
||||
|
||||
assert(pos_is_ok());
|
||||
}
|
||||
|
||||
@@ -914,6 +915,8 @@ void Position::do_null_move(StateInfo& newSt) {
|
||||
|
||||
sideToMove = ~sideToMove;
|
||||
|
||||
set_check_info(st);
|
||||
|
||||
assert(pos_is_ok());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user