1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +00:00

Streamline generation of MV_NON_EVASION

Small speed-up of 3% in perft.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-01-03 15:16:01 +01:00
parent 30418a3cfc
commit b1fcfe4c5d

View file

@ -101,8 +101,6 @@ namespace {
FORCE_INLINE MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) { FORCE_INLINE MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) {
assert(Pt == PAWN); assert(Pt == PAWN);
assert(Type == MV_CAPTURE || Type == MV_NON_CAPTURE || Type == MV_EVASION);
return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m, t, SQ_NONE) return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m, t, SQ_NONE)
: generate_pawn_moves<BLACK, Type>(p, m, t, SQ_NONE)); : generate_pawn_moves<BLACK, Type>(p, m, t, SQ_NONE));
} }
@ -151,27 +149,22 @@ namespace {
template<MoveType Type> template<MoveType Type>
MoveStack* generate(const Position& pos, MoveStack* mlist) { MoveStack* generate(const Position& pos, MoveStack* mlist) {
assert(Type == MV_CAPTURE || Type == MV_NON_CAPTURE || Type == MV_NON_EVASION);
assert(!pos.in_check()); assert(!pos.in_check());
Color us = pos.side_to_move(); Color us = pos.side_to_move();
Bitboard target; Bitboard target;
if (Type == MV_CAPTURE || Type == MV_NON_EVASION) if (Type == MV_CAPTURE)
target = pos.pieces(flip(us)); target = pos.pieces(flip(us));
else if (Type == MV_NON_CAPTURE) else if (Type == MV_NON_CAPTURE)
target = pos.empty_squares(); target = pos.empty_squares();
else
assert(false);
if (Type == MV_NON_EVASION) else if (Type == MV_NON_EVASION)
{ target = pos.pieces(flip(us)) | pos.empty_squares();
mlist = generate_piece_moves<PAWN, MV_CAPTURE>(pos, mlist, us, target);
mlist = generate_piece_moves<PAWN, MV_NON_CAPTURE>(pos, mlist, us, pos.empty_squares());
target |= pos.empty_squares();
}
else
mlist = generate_piece_moves<PAWN, Type>(pos, mlist, us, target); mlist = generate_piece_moves<PAWN, Type>(pos, mlist, us, target);
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target); mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target); mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
mlist = generate_piece_moves<ROOK>(pos, mlist, us, target); mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
@ -339,7 +332,7 @@ namespace {
Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p; Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p;
} }
template<MoveType Type, Square Delta> template<Square Delta>
inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) { inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) {
const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB); const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB);
@ -371,10 +364,10 @@ namespace {
{ {
to = pop_1st_bit(&b); to = pop_1st_bit(&b);
if (Type == MV_CAPTURE || Type == MV_EVASION) if (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
(*mlist++).move = make_promotion(to - Delta, to, QUEEN); (*mlist++).move = make_promotion(to - Delta, to, QUEEN);
if (Type == MV_NON_CAPTURE || Type == MV_EVASION) if (Type == MV_NON_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
{ {
(*mlist++).move = make_promotion(to - Delta, to, ROOK); (*mlist++).move = make_promotion(to - Delta, to, ROOK);
(*mlist++).move = make_promotion(to - Delta, to, BISHOP); (*mlist++).move = make_promotion(to - Delta, to, BISHOP);
@ -435,10 +428,10 @@ namespace {
} }
// Standard captures // Standard captures
if (Type == MV_CAPTURE || Type == MV_EVASION) if (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
{ {
mlist = generate_pawn_captures<Type, RIGHT_UP>(mlist, pawns, enemyPieces); mlist = generate_pawn_captures<RIGHT_UP>(mlist, pawns, enemyPieces);
mlist = generate_pawn_captures<Type, LEFT_UP>(mlist, pawns, enemyPieces); mlist = generate_pawn_captures<LEFT_UP>(mlist, pawns, enemyPieces);
} }
// Single and double pawn pushes // Single and double pawn pushes
@ -470,7 +463,8 @@ namespace {
} }
// En passant captures // En passant captures
if ((Type == MV_CAPTURE || Type == MV_EVASION) && pos.ep_square() != SQ_NONE) if ( (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
&& pos.ep_square() != SQ_NONE)
{ {
assert(Us != WHITE || rank_of(pos.ep_square()) == RANK_6); assert(Us != WHITE || rank_of(pos.ep_square()) == RANK_6);
assert(Us != BLACK || rank_of(pos.ep_square()) == RANK_3); assert(Us != BLACK || rank_of(pos.ep_square()) == RANK_3);