mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Introduce generate_promotions()
A bit ugly to guarantee no functional change. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
b36900ef44
commit
6f70e762a9
1 changed files with 54 additions and 53 deletions
|
@ -452,27 +452,45 @@ namespace {
|
||||||
Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p;
|
Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us, MoveType Type, SquareDelta Delta>
|
template<MoveType Type, SquareDelta Delta>
|
||||||
inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) {
|
inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) {
|
||||||
|
|
||||||
|
// Calculate our parametrized parameters at compile time
|
||||||
|
const Bitboard TRank8BB = (Delta == DELTA_NE || Delta == DELTA_NW ? Rank8BB : Rank1BB);
|
||||||
|
const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB);
|
||||||
|
|
||||||
|
Bitboard b;
|
||||||
|
Square to;
|
||||||
|
|
||||||
|
// Captures in the a1-h8 (a8-h1 for black) diagonal or in the h1-a8 (h8-a1 for black)
|
||||||
|
if (Type == CAPTURE || Type == EVASION)
|
||||||
|
{
|
||||||
|
b = move_pawns<Delta>(pawns) & target & ~TFileABB & ~TRank8BB;
|
||||||
|
SERIALIZE_MOVES_D(b, -Delta);
|
||||||
|
}
|
||||||
|
return mlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<Color Us, MoveType Type, SquareDelta Delta>
|
||||||
|
inline MoveStack* generate_promotions(const Position& pos, MoveStack* mlist, Bitboard pawns, Bitboard target) {
|
||||||
|
|
||||||
// Calculate our parametrized parameters at compile time
|
// Calculate our parametrized parameters at compile time
|
||||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||||
const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB);
|
const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB);
|
||||||
|
const bool IsPush = (Delta == DELTA_N || Delta == DELTA_S);
|
||||||
|
|
||||||
Bitboard b1, b2;
|
Bitboard b;
|
||||||
Square to;
|
Square to;
|
||||||
|
|
||||||
// Captures in the a1-h8 (a8-h1 for black) diagonal or in the h1-a8 (h8-a1 for black)
|
// Promotions and under-promotions
|
||||||
b1 = move_pawns<Delta>(pawns) & ~TFileABB & target;
|
b = move_pawns<Delta>(pawns) & target & TRank8BB;
|
||||||
|
|
||||||
// Capturing promotions and under-promotions
|
if (Delta != DELTA_N && Delta != DELTA_S)
|
||||||
if (b1 & TRank8BB)
|
b &= ~TFileABB;
|
||||||
|
|
||||||
|
while (b)
|
||||||
{
|
{
|
||||||
b2 = b1 & TRank8BB;
|
to = pop_1st_bit(&b);
|
||||||
b1 &= ~TRank8BB;
|
|
||||||
while (b2)
|
|
||||||
{
|
|
||||||
to = pop_1st_bit(&b2);
|
|
||||||
|
|
||||||
if (Type == CAPTURE || Type == EVASION)
|
if (Type == CAPTURE || Type == EVASION)
|
||||||
(*mlist++).move = make_promotion_move(to - Delta, to, QUEEN);
|
(*mlist++).move = make_promotion_move(to - Delta, to, QUEEN);
|
||||||
|
@ -487,15 +505,14 @@ namespace {
|
||||||
// This is the only possible under promotion that can give a check
|
// This is the only possible under promotion that can give a check
|
||||||
// not already included in the queen-promotion. It is not sure that
|
// not already included in the queen-promotion. It is not sure that
|
||||||
// the promoted knight will give check, but it doesn't worth to verify.
|
// the promoted knight will give check, but it doesn't worth to verify.
|
||||||
if (Type == CHECK)
|
if (Type == CHECK && !IsPush)
|
||||||
|
(*mlist++).move = make_promotion_move(to - Delta, to, KNIGHT);
|
||||||
|
|
||||||
|
// This is the only possible under promotion that can give a check
|
||||||
|
// not already included in the queen-promotion.
|
||||||
|
if (Type == CHECK && IsPush && bit_is_set(pos.attacks_from<KNIGHT>(to), pos.king_square(opposite_color(Us))))
|
||||||
(*mlist++).move = make_promotion_move(to - Delta, to, KNIGHT);
|
(*mlist++).move = make_promotion_move(to - Delta, to, KNIGHT);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Serialize standard captures
|
|
||||||
if (Type == CAPTURE || Type == EVASION)
|
|
||||||
SERIALIZE_MOVES_D(b1, -Delta);
|
|
||||||
|
|
||||||
return mlist;
|
return mlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,37 +540,21 @@ namespace {
|
||||||
if (Type == EVASION)
|
if (Type == EVASION)
|
||||||
enemyPieces &= target; // Capture only the checker piece
|
enemyPieces &= target; // Capture only the checker piece
|
||||||
|
|
||||||
mlist = generate_pawn_captures<Us, Type, TDELTA_NE>(mlist, pawns, enemyPieces);
|
mlist = generate_promotions<Us, Type, TDELTA_NE>(pos, mlist, pawns, enemyPieces);
|
||||||
mlist = generate_pawn_captures<Us, Type, TDELTA_NW>(mlist, pawns, enemyPieces);
|
mlist = generate_pawn_captures<Type, TDELTA_NE>(mlist, pawns, enemyPieces);
|
||||||
|
mlist = generate_promotions<Us, Type, TDELTA_NW>(pos, mlist, pawns, enemyPieces);
|
||||||
|
mlist = generate_pawn_captures<Type, TDELTA_NW>(mlist, pawns, enemyPieces);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non-capturing promotions and underpromotions
|
// Non-capturing promotions and underpromotions
|
||||||
if (pawns & TRank7BB)
|
if (pawns & TRank7BB)
|
||||||
{
|
{
|
||||||
b1 = move_pawns<TDELTA_N>(pawns) & TRank8BB & pos.empty_squares();
|
b1 = pos.empty_squares();
|
||||||
|
|
||||||
if (Type == EVASION)
|
if (Type == EVASION)
|
||||||
b1 &= target; // Only blocking promotion pushes
|
b1 &= target; // Only blocking promotion pushes
|
||||||
|
|
||||||
while (b1)
|
mlist = generate_promotions<Us, Type, TDELTA_N>(pos, mlist, pawns, b1);
|
||||||
{
|
|
||||||
to = pop_1st_bit(&b1);
|
|
||||||
|
|
||||||
if (Type == CAPTURE || Type == EVASION)
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, QUEEN);
|
|
||||||
|
|
||||||
if (Type == NON_CAPTURE || Type == EVASION)
|
|
||||||
{
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, ROOK);
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, BISHOP);
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the only possible under promotion that can give a check
|
|
||||||
// not already included in the queen-promotion.
|
|
||||||
if (Type == CHECK && bit_is_set(pos.attacks_from<KNIGHT>(to), pos.king_square(Them)))
|
|
||||||
(*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard pawn pushes and double pushes
|
// Standard pawn pushes and double pushes
|
||||||
|
|
Loading…
Add table
Reference in a new issue