-/// generate_moves() computes a complete list of legal or pseudo legal moves in
-/// the current position. This function is not very fast, and should be used
-/// only in situations where performance is unimportant.
-
-MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLegal) {
-
- assert(pos.is_ok());
-
- Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
-
- if (pos.is_check())
- return generate_evasions(pos, mlist, pinned);
-
- // Generate pseudo-legal moves
- MoveStack* last = generate_captures(pos, mlist);
- last = generate_noncaptures(pos, last);
- if (pseudoLegal)
- return last;
-
- // Remove illegal moves from the list
- for (MoveStack* cur = mlist; cur != last; cur++)
- if (!pos.pl_move_is_legal(cur->move, pinned))
- {
- cur->move = (--last)->move;
- cur--;
- }
- 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 for non time-critical paths.
-
-bool move_is_legal(const Position& pos, const Move m) {
-
- MoveStack mlist[256];
- MoveStack* last = generate_moves(pos, mlist, true);
- for (MoveStack* cur = mlist; cur != last; cur++)
- if (cur->move == m)
- return pos.pl_move_is_legal(m);
-
- return false;
-}
-
-
-/// Fast version of move_is_legal() that takes a position a move and
-/// a pinned pieces bitboard as input, and tests whether the move is legal.
-/// This version must only be used when the side to move is not in check.
-
-bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
-
- assert(pos.is_ok());
- assert(!pos.is_check());
- assert(move_is_ok(m));
- assert(pinned == pos.pinned_pieces(pos.side_to_move()));
-
- // Use a slower but simpler function for uncommon cases
- if (move_is_ep(m) || move_is_castle(m))
- return move_is_legal(pos, m);
-
- Color us = pos.side_to_move();
- Square from = move_from(m);
- Piece pc = pos.piece_on(from);
-
- // If the from square is not occupied by a piece belonging to the side to
- // move, the move is obviously not legal.
- if (color_of_piece(pc) != us)
- return false;