Too long code seems to be in the following function:
Code: Select all
bool Position::pl_move_is_evasion(Move m, Bitboard pinned) const
{
assert(is_check());
Color us = side_to_move();
Square from = move_from(m);
Square to = move_to(m);
// King moves and en-passant captures are verified in pl_move_is_legal()
if (type_of_piece_on(from) == KING || move_is_ep(m))
return pl_move_is_legal(m, pinned);
Bitboard target = checkers();
Square checksq = pop_1st_bit(&target);
if (target) // double check ?
return false;
// Our move must be a blocking evasion or a capture of the checking piece
target = squares_between(checksq, king_square(us)) | checkers();
return bit_is_set(target, to) && pl_move_is_legal(m, pinned);
}
Code: Select all
---
Bitboard target = checkers();
if (target & (target - 1)) // double check ? // changed
return false;
if (move_is_castle(m)) // added
return false; // castle is prohibit when is check !
// Our move must be a blocking evasion or a capture of the checking piece
target = squares_between(checksq, king_square(us)) | checkers();
return bit_is_set(target, to) && (!pinned || !bit_is_set(pinned, from)); // changed
The constructor data CheckInfo::CheckInfo(const Position& pos) are using by 2 permanet function:
bool Position::move_is_check(Move m, const CheckInfo& ci) and
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck)
It seems to be that this constructor makes many useless and time-consuming code.
My proposition is to remove it (or all the struct CheckInfo).
Code: Select all
CheckInfo::CheckInfo(const Position& pos) {
Color us = pos.side_to_move();
Color them = opposite_color(us);
ksq = pos.king_square(them);
dcCandidates = pos.discovered_check_candidates(us);
checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them);
checkSq[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
checkSq[KING] = EmptyBoardBB;
}
Code: Select all
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck)
---
if (moveIsCheck)
{
if (ep | pm)
st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us);
else
{
// added.
// note that now it works only if moveIsCheck!
pt == PAWN ? ci.checkSq[PAWN] = pos.attacks_from<PAWN>(ci.ksq, them) : ci.checkSq[pt] = pos.attacks_from<pt>(ci.ksq);
ci.dcCandidates = pos.discovered_check_candidates(us);
ci.ksq = pos.king_square(them);
// Direct checks
---
Code: Select all
bool Position::move_is_check(Move m, const CheckInfo& ci) const {
---
PieceType pt = type_of_piece_on(from);
// added
Color us = pos.side_to_move();
Color them = opposite_color(us);
pt == PAWN ? ci.checkSq[PAWN] = pos.attacks_from<PAWN>(ci.ksq, them) : ci.checkSq[pt] = pos.attacks_from<pt>(ci.ksq);
// Direct check ?
if (bit_is_set(ci.checkSq[pt], to))
return true;
// added
dcCandidates = pos.discovered_check_candidates(us);
ci.ksq = pos.king_square(them);
// Discovery check ?
---
bool Position::has_mate_threat() and perft().
And Stockfish is no. 1