-template<MoveType Type>
-MoveStack* generate(const Position& pos, MoveStack* mlist) {
-
- assert(pos.is_ok());
- assert(!pos.in_check());
-
- Color us = pos.side_to_move();
- Bitboard target;
-
- if (Type == MV_CAPTURE || Type == MV_NON_EVASION)
- target = pos.pieces_of_color(opposite_color(us));
- else if (Type == MV_NON_CAPTURE)
- target = pos.empty_squares();
- else
- assert(false);
-
- if (Type == MV_NON_EVASION)
- {
- 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<KNIGHT>(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<QUEEN>(pos, mlist, us, target);
- mlist = generate_piece_moves<KING>(pos, mlist, us, target);
-
- if (Type != MV_CAPTURE)
- {
- if (pos.can_castle_kingside(us))
- mlist = generate_castle_moves<KING_SIDE>(pos, mlist, us);
-
- if (pos.can_castle_queenside(us))
- mlist = generate_castle_moves<QUEEN_SIDE>(pos, mlist, us);
- }
-
- return mlist;
-}
-
-// Explicit template instantiations
-template MoveStack* generate<MV_CAPTURE>(const Position& pos, MoveStack* mlist);
-template MoveStack* generate<MV_NON_CAPTURE>(const Position& pos, MoveStack* mlist);
-template MoveStack* generate<MV_NON_EVASION>(const Position& pos, MoveStack* mlist);
-
-
-/// generate_non_capture_checks() generates all pseudo-legal non-captures and knight
-/// underpromotions that give check. Returns a pointer to the end of the move list.
-template<>
-MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist) {
-
- assert(pos.is_ok());
- assert(!pos.in_check());
-
- Bitboard b, dc;
- Square from;
- Color us = pos.side_to_move();
- Square ksq = pos.king_square(opposite_color(us));
-
- assert(pos.piece_on(ksq) == make_piece(opposite_color(us), KING));
-
- // Discovered non-capture checks
- b = dc = pos.discovered_check_candidates(us);
-
- while (b)
- {
- from = pop_1st_bit(&b);
- switch (type_of_piece(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;
- }
- }
-
- // Direct non-capture checks
- mlist = generate_direct_checks<PAWN>(pos, mlist, us, dc, ksq);
- mlist = generate_direct_checks<KNIGHT>(pos, mlist, us, dc, ksq);
- mlist = generate_direct_checks<BISHOP>(pos, mlist, us, dc, ksq);
- mlist = generate_direct_checks<ROOK>(pos, mlist, us, dc, ksq);
- return generate_direct_checks<QUEEN>(pos, mlist, us, dc, ksq);
-}
-
-
-/// generate_evasions() generates all pseudo-legal check evasions when
-/// the side to move is in check. Returns a pointer to the end of the move list.
-template<>
-MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
-
- assert(pos.is_ok());
- assert(pos.in_check());