mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Fix a bug in king discoveries checks
Introduced in "Add a generate_piece_checks() specialization for the king" Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
5dc2312121
commit
0c8659721f
1 changed files with 49 additions and 53 deletions
102
src/movegen.cpp
102
src/movegen.cpp
|
@ -60,61 +60,10 @@ namespace {
|
||||||
|
|
||||||
template<PieceType>
|
template<PieceType>
|
||||||
int generate_piece_checks(const Position&, Bitboard, Bitboard, Square, MoveStack*, int);
|
int generate_piece_checks(const Position&, Bitboard, Bitboard, Square, MoveStack*, int);
|
||||||
|
int generate_piece_checks_king(const Position&, Square, Bitboard, Square, MoveStack*, int);
|
||||||
|
|
||||||
template<PieceType>
|
template<PieceType>
|
||||||
int generate_piece_blocking_evasions(const Position&, Bitboard, Bitboard, MoveStack*, int);
|
int generate_piece_blocking_evasions(const Position&, Bitboard, Bitboard, MoveStack*, int);
|
||||||
|
|
||||||
|
|
||||||
/// Templates with specializations are defined here to avoid lookup issues
|
|
||||||
|
|
||||||
template<PieceType Piece>
|
|
||||||
int generate_piece_checks(const Position& pos, Bitboard target, Bitboard dc,
|
|
||||||
Square ksq, MoveStack* mlist, int n) {
|
|
||||||
// Discovered checks
|
|
||||||
Bitboard b = target & dc;
|
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
Square from = pop_1st_bit(&b);
|
|
||||||
Bitboard bb = pos.piece_attacks<Piece>(from) & pos.empty_squares();
|
|
||||||
while (bb)
|
|
||||||
{
|
|
||||||
Square to = pop_1st_bit(&bb);
|
|
||||||
mlist[n++].move = make_move(from, to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Direct checks
|
|
||||||
b = target & ~dc;
|
|
||||||
Bitboard checkSqs = pos.piece_attacks<Piece>(ksq) & pos.empty_squares();
|
|
||||||
while (b)
|
|
||||||
{
|
|
||||||
Square from = pop_1st_bit(&b);
|
|
||||||
Bitboard bb = pos.piece_attacks<Piece>(from) & checkSqs;
|
|
||||||
while (bb)
|
|
||||||
{
|
|
||||||
Square to = pop_1st_bit(&bb);
|
|
||||||
mlist[n++].move = make_move(from, to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<> // Special case the King
|
|
||||||
int generate_piece_checks<KING>(const Position& pos, Bitboard, Bitboard dc,
|
|
||||||
Square ksq, MoveStack* mlist, int n) {
|
|
||||||
if (bit_is_set(dc, ksq))
|
|
||||||
{
|
|
||||||
Bitboard bb = pos.piece_attacks<KING>(ksq)
|
|
||||||
& pos.empty_squares()
|
|
||||||
& ~QueenPseudoAttacks[ksq];
|
|
||||||
while (bb)
|
|
||||||
{
|
|
||||||
Square to = pop_1st_bit(&bb);
|
|
||||||
mlist[n++].move = make_move(ksq, to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -218,7 +167,7 @@ int generate_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
|
||||||
n = generate_piece_checks<QUEEN>(pos, b, dc, ksq, mlist, n);
|
n = generate_piece_checks<QUEEN>(pos, b, dc, ksq, mlist, n);
|
||||||
|
|
||||||
// Hopefully we always have a king ;-)
|
// Hopefully we always have a king ;-)
|
||||||
n = generate_piece_checks<KING>(pos, b, dc, pos.king_square(us), mlist, n);
|
n = generate_piece_checks_king(pos, pos.king_square(us), dc, ksq, mlist, n);
|
||||||
|
|
||||||
// TODO: Castling moves!
|
// TODO: Castling moves!
|
||||||
|
|
||||||
|
@ -813,6 +762,53 @@ namespace {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<PieceType Piece>
|
||||||
|
int generate_piece_checks(const Position& pos, Bitboard target, Bitboard dc,
|
||||||
|
Square ksq, MoveStack* mlist, int n) {
|
||||||
|
// Discovered checks
|
||||||
|
Bitboard b = target & dc;
|
||||||
|
while (b)
|
||||||
|
{
|
||||||
|
Square from = pop_1st_bit(&b);
|
||||||
|
Bitboard bb = pos.piece_attacks<Piece>(from) & pos.empty_squares();
|
||||||
|
while (bb)
|
||||||
|
{
|
||||||
|
Square to = pop_1st_bit(&bb);
|
||||||
|
mlist[n++].move = make_move(from, to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Direct checks
|
||||||
|
b = target & ~dc;
|
||||||
|
Bitboard checkSqs = pos.piece_attacks<Piece>(ksq) & pos.empty_squares();
|
||||||
|
while (b)
|
||||||
|
{
|
||||||
|
Square from = pop_1st_bit(&b);
|
||||||
|
Bitboard bb = pos.piece_attacks<Piece>(from) & checkSqs;
|
||||||
|
while (bb)
|
||||||
|
{
|
||||||
|
Square to = pop_1st_bit(&bb);
|
||||||
|
mlist[n++].move = make_move(from, to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int generate_piece_checks_king(const Position& pos, Square from, Bitboard dc,
|
||||||
|
Square ksq, MoveStack* mlist, int n) {
|
||||||
|
if (bit_is_set(dc, from))
|
||||||
|
{
|
||||||
|
Bitboard b = pos.piece_attacks<KING>(from)
|
||||||
|
& pos.empty_squares()
|
||||||
|
& ~QueenPseudoAttacks[ksq];
|
||||||
|
while (b)
|
||||||
|
{
|
||||||
|
Square to = pop_1st_bit(&b);
|
||||||
|
mlist[n++].move = make_move(from, to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<Color C>
|
template<Color C>
|
||||||
int generate_pawn_blocking_evasions(const Position& pos, Bitboard not_pinned,
|
int generate_pawn_blocking_evasions(const Position& pos, Bitboard not_pinned,
|
||||||
|
|
Loading…
Add table
Reference in a new issue