- // Generate evasions for king, capture and non capture moves
- b = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~sliderAttacks;
- from = ksq;
- SERIALIZE_MOVES(b);
-
- // Generate evasions for other pieces only if not double check
- if (checkersCnt > 1)
- return mlist;
-
- // Find squares where a blocking evasion or a capture of the
- // checker piece is possible.
- target = squares_between(checksq, ksq) | checkers;
-
- mlist = generate_piece_moves<PAWN, MV_EVASION>(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);
- return generate_piece_moves<QUEEN>(pos, mlist, us, target);
-}
-
-
-/// generate<MV_LEGAL / MV_PSEUDO_LEGAL> computes a complete list of legal
-/// or pseudo-legal moves in the current position.
-template<>
-inline MoveStack* generate<MV_PSEUDO_LEGAL>(const Position& pos, MoveStack* mlist) {
-
- assert(pos.is_ok());
-
- return pos.is_check() ? generate<MV_EVASION>(pos, mlist)
- : generate<MV_NON_EVASION>(pos, mlist);
-}
-
-template<>
-MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {
-
- assert(pos.is_ok());
-
- MoveStack *last, *cur = mlist;
- Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
-
- last = generate<MV_PSEUDO_LEGAL>(pos, mlist);
-
- // Remove illegal moves from the list
- while (cur != last)
- if (pos.pl_move_is_legal(cur->move, pinned))
- cur++;
- else
- cur->move = (--last)->move;
-
- return last;
-}
-
-
-/// move_is_legal() takes a position and a (not necessarily pseudo-legal)
-/// move and tests whether the move is legal. This version is not very fast
-/// and should be used only in non time-critical paths.
-
-bool move_is_legal(const Position& pos, const Move m) {
-
- MoveStack mlist[MOVES_MAX];
- MoveStack *cur, *last = generate<MV_PSEUDO_LEGAL>(pos, mlist);
-
- for (cur = mlist; cur != last; cur++)
- if (cur->move == m)
- return pos.pl_move_is_legal(m, pos.pinned_pieces(pos.side_to_move()));
-
- return false;
-}