mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Simplify generate_pawn_captures()
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
a1c02815cc
commit
b36900ef44
1 changed files with 24 additions and 30 deletions
|
@ -444,34 +444,26 @@ namespace {
|
|||
return mlist;
|
||||
}
|
||||
|
||||
template<Color Us, SquareDelta Direction>
|
||||
template<SquareDelta Delta>
|
||||
inline Bitboard move_pawns(Bitboard p) {
|
||||
|
||||
if (Direction == DELTA_N)
|
||||
return Us == WHITE ? p << 8 : p >> 8;
|
||||
else if (Direction == DELTA_NE)
|
||||
return Us == WHITE ? p << 9 : p >> 7;
|
||||
else if (Direction == DELTA_NW)
|
||||
return Us == WHITE ? p << 7 : p >> 9;
|
||||
else
|
||||
return p;
|
||||
return Delta == DELTA_N ? p << 8 : Delta == DELTA_S ? p >> 8 :
|
||||
Delta == DELTA_NE ? p << 9 : Delta == DELTA_SE ? p >> 7 :
|
||||
Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p;
|
||||
}
|
||||
|
||||
template<Color Us, MoveType Type, SquareDelta Diagonal>
|
||||
inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard enemyPieces) {
|
||||
template<Color Us, MoveType Type, SquareDelta Delta>
|
||||
inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) {
|
||||
|
||||
// Calculate our parametrized parameters at compile time
|
||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||
const Bitboard TFileABB = (Diagonal == DELTA_NE ? FileABB : FileHBB);
|
||||
const SquareDelta TDELTA_NE = (Us == WHITE ? DELTA_NE : DELTA_SE);
|
||||
const SquareDelta TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW);
|
||||
const SquareDelta TTDELTA_NE = (Diagonal == DELTA_NE ? TDELTA_NE : TDELTA_NW);
|
||||
const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB);
|
||||
|
||||
Bitboard b1, b2;
|
||||
Square to;
|
||||
|
||||
// Captures in the a1-h8 (a8-h1 for black) diagonal or in the h1-a8 (h8-a1 for black)
|
||||
b1 = move_pawns<Us, Diagonal>(pawns) & ~TFileABB & enemyPieces;
|
||||
b1 = move_pawns<Delta>(pawns) & ~TFileABB & target;
|
||||
|
||||
// Capturing promotions and under-promotions
|
||||
if (b1 & TRank8BB)
|
||||
|
@ -483,26 +475,26 @@ namespace {
|
|||
to = pop_1st_bit(&b2);
|
||||
|
||||
if (Type == CAPTURE || Type == EVASION)
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, QUEEN);
|
||||
(*mlist++).move = make_promotion_move(to - Delta, to, QUEEN);
|
||||
|
||||
if (Type == NON_CAPTURE || Type == EVASION)
|
||||
{
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, ROOK);
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, BISHOP);
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, KNIGHT);
|
||||
(*mlist++).move = make_promotion_move(to - Delta, to, ROOK);
|
||||
(*mlist++).move = make_promotion_move(to - Delta, to, BISHOP);
|
||||
(*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. It is not sure that
|
||||
// the promoted knight will give check, but it doesn't worth to verify.
|
||||
if (Type == CHECK)
|
||||
(*mlist++).move = make_promotion_move(to - TTDELTA_NE, to, KNIGHT);
|
||||
(*mlist++).move = make_promotion_move(to - Delta, to, KNIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize standard captures
|
||||
if (Type == CAPTURE || Type == EVASION)
|
||||
SERIALIZE_MOVES_D(b1, -TTDELTA_NE);
|
||||
SERIALIZE_MOVES_D(b1, -Delta);
|
||||
|
||||
return mlist;
|
||||
}
|
||||
|
@ -515,7 +507,9 @@ namespace {
|
|||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S);
|
||||
const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S);
|
||||
const SquareDelta TDELTA_NE = (Us == WHITE ? DELTA_NE : DELTA_SE);
|
||||
const SquareDelta TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW);
|
||||
|
||||
Square to;
|
||||
Bitboard b1, b2, enemyPieces, emptySquares;
|
||||
|
@ -529,14 +523,14 @@ namespace {
|
|||
if (Type == EVASION)
|
||||
enemyPieces &= target; // Capture only the checker piece
|
||||
|
||||
mlist = generate_pawn_captures<Us, Type, DELTA_NE>(mlist, pawns, enemyPieces);
|
||||
mlist = generate_pawn_captures<Us, Type, DELTA_NW>(mlist, pawns, enemyPieces);
|
||||
mlist = generate_pawn_captures<Us, Type, TDELTA_NE>(mlist, pawns, enemyPieces);
|
||||
mlist = generate_pawn_captures<Us, Type, TDELTA_NW>(mlist, pawns, enemyPieces);
|
||||
}
|
||||
|
||||
// Non-capturing promotions and underpromotions
|
||||
if (pawns & TRank7BB)
|
||||
{
|
||||
b1 = move_pawns<Us, DELTA_N>(pawns) & TRank8BB & pos.empty_squares();
|
||||
b1 = move_pawns<TDELTA_N>(pawns) & TRank8BB & pos.empty_squares();
|
||||
|
||||
if (Type == EVASION)
|
||||
b1 &= target; // Only blocking promotion pushes
|
||||
|
@ -568,8 +562,8 @@ namespace {
|
|||
emptySquares = (Type == NON_CAPTURE ? target : pos.empty_squares());
|
||||
|
||||
// Single and double pawn pushes
|
||||
b1 = move_pawns<Us, DELTA_N>(pawns) & emptySquares & ~TRank8BB;
|
||||
b2 = move_pawns<Us, DELTA_N>(b1 & TRank3BB) & emptySquares;
|
||||
b1 = move_pawns<TDELTA_N>(pawns) & emptySquares & ~TRank8BB;
|
||||
b2 = move_pawns<TDELTA_N>(b1 & TRank3BB) & emptySquares;
|
||||
|
||||
// Filter out unwanted pushes according to the move type
|
||||
if (Type == EVASION)
|
||||
|
@ -588,8 +582,8 @@ namespace {
|
|||
// don't generate captures.
|
||||
if (pawns & target) // For CHECK type target is dc bitboard
|
||||
{
|
||||
Bitboard dc1 = move_pawns<Us, DELTA_N>(pawns & target & ~file_bb(ksq)) & emptySquares & ~TRank8BB;
|
||||
Bitboard dc2 = move_pawns<Us, DELTA_N>(dc1 & TRank3BB) & emptySquares;
|
||||
Bitboard dc1 = move_pawns<TDELTA_N>(pawns & target & ~file_bb(ksq)) & emptySquares & ~TRank8BB;
|
||||
Bitboard dc2 = move_pawns<TDELTA_N>(dc1 & TRank3BB) & emptySquares;
|
||||
|
||||
b1 |= dc1;
|
||||
b2 |= dc2;
|
||||
|
|
Loading…
Add table
Reference in a new issue