along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <cassert>
#include <algorithm>
+#include <cassert>
#include "bitcount.h"
#include "movegen.h"
#include "position.h"
-#include "misc.h"
-// Simple macro to wrap a very common while loop, no facny, no flexibility,
-// hardcoded list name 'mlist' and from square 'from'.
+/// Simple macro to wrap a very common while loop, no facny, no flexibility,
+/// hardcoded names 'mlist' and 'from'.
#define SERIALIZE_MOVES(b) while (b) (*mlist++).move = make_move(from, pop_1st_bit(&b))
-// Version used for pawns, where the 'from' square is given as a delta from the 'to' square
+/// Version used for pawns, where the 'from' square is given as a delta from the 'to' square
#define SERIALIZE_MOVES_D(b, d) while (b) { to = pop_1st_bit(&b); (*mlist++).move = make_move(to + (d), to); }
namespace {
// Knight-promotion is the only one that can give a check (direct or
// discovered) not already included in the queen-promotion.
- if ( Type == MV_CHECK
+ if ( Type == MV_NON_CAPTURE_CHECK
&& bit_is_set(StepAttacksBB[W_KNIGHT][to], ksq))
(*mlist++).move = make_promotion(to - Delta, to, KNIGHT);
else
b1 = move_pawns<UP>(pawnsNotOn7) & emptySquares;
b2 = move_pawns<UP>(b1 & TRank3BB) & emptySquares;
- if (Type == MV_EVASION)
+ if (Type == MV_EVASION) // Consider only blocking squares
{
- b1 &= target; // Consider only blocking squares
+ b1 &= target;
b2 &= target;
}
- if (Type == MV_CHECK)
+ if (Type == MV_NON_CAPTURE_CHECK)
{
// Consider only direct checks
b1 &= pos.attacks_from<PAWN>(ksq, Them);
// if the pawn is not on the same file as the enemy king, because we
// don't generate captures. Note that a possible discovery check
// promotion has been already generated among captures.
- if (pawnsNotOn7 & target) // For CHECK type target is dc bitboard
+ if (pawnsNotOn7 & target) // Target is dc bitboard
{
dc1 = move_pawns<UP>(pawnsNotOn7 & target) & emptySquares & ~file_bb(ksq);
dc2 = move_pawns<UP>(dc1 & TRank3BB) & emptySquares;
}
- template<PieceType Pt>
- inline MoveStack* generate_discovered_checks(const Position& pos, MoveStack* mlist, Square from) {
-
- assert(Pt != QUEEN && Pt != PAWN);
-
- Bitboard b = pos.attacks_from<Pt>(from) & pos.empty_squares();
-
- if (Pt == KING)
- b &= ~QueenPseudoAttacks[pos.king_square(flip(pos.side_to_move()))];
-
- SERIALIZE_MOVES(b);
- return mlist;
- }
-
-
template<PieceType Pt>
inline MoveStack* generate_direct_checks(const Position& pos, MoveStack* mlist, Color us,
Bitboard dc, Square ksq) {
template<>
FORCE_INLINE MoveStack* generate_direct_checks<PAWN>(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) {
- return (us == WHITE ? generate_pawn_moves<WHITE, MV_CHECK>(p, m, dc, ksq)
- : generate_pawn_moves<BLACK, MV_CHECK>(p, m, dc, ksq));
+ return (us == WHITE ? generate_pawn_moves<WHITE, MV_NON_CAPTURE_CHECK>(p, m, dc, ksq)
+ : generate_pawn_moves<BLACK, MV_NON_CAPTURE_CHECK>(p, m, dc, ksq));
}
Bitboard b, dc;
Square from;
+ PieceType pt;
Color us = pos.side_to_move();
Square ksq = pos.king_square(flip(us));
while (b)
{
from = pop_1st_bit(&b);
- switch (type_of(pos.piece_on(from)))
- {
- case PAWN: /* Will be generated togheter with pawns direct checks */ break;
- case KNIGHT: mlist = generate_discovered_checks<KNIGHT>(pos, mlist, from); break;
- case BISHOP: mlist = generate_discovered_checks<BISHOP>(pos, mlist, from); break;
- case ROOK: mlist = generate_discovered_checks<ROOK>(pos, mlist, from); break;
- case KING: mlist = generate_discovered_checks<KING>(pos, mlist, from); break;
- default: assert(false); break;
- }
+ pt = type_of(pos.piece_on(from));
+
+ if (pt == PAWN)
+ continue; // Will be generated togheter with direct checks
+
+ b = pos.attacks_from(Piece(pt), from) & pos.empty_squares();
+
+ if (pt == KING)
+ b &= ~QueenPseudoAttacks[ksq];
+
+ SERIALIZE_MOVES(b);
}
// Direct non-capture checks
}
-/// generate<MV_LEGAL> computes a complete list of legal moves in the current position
+/// generate<MV_LEGAL> generates all legal moves in the current position
template<>
MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {