And some documentation update.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
-/// generate<MV_LEGAL / MV_PSEUDO_LEGAL> computes a complete list of legal
-/// or pseudo-legal moves in the current position.
-template<>
-MoveStack* generate<MV_PSEUDO_LEGAL>(const Position& pos, MoveStack* mlist) {
-
- assert(pos.is_ok());
-
- return pos.in_check() ? generate<MV_EVASION>(pos, mlist)
- : generate<MV_NON_EVASION>(pos, mlist);
-}
+/// generate<MV_LEGAL> computes a complete list of legal moves in the current position
template<>
MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {
template<>
MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {
MoveStack *last, *cur = mlist;
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
MoveStack *last, *cur = mlist;
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
- last = generate<MV_PSEUDO_LEGAL>(pos, mlist);
+ last = pos.in_check() ? generate<MV_EVASION>(pos, mlist)
+ : generate<MV_NON_EVASION>(pos, mlist);
// Remove illegal moves from the list
while (cur != last)
// Remove illegal moves from the list
while (cur != last)
MV_NON_CAPTURE_CHECK,
MV_EVASION,
MV_NON_EVASION,
MV_NON_CAPTURE_CHECK,
MV_EVASION,
MV_NON_EVASION,
- MV_LEGAL,
- MV_PSEUDO_LEGAL
bool MovePicker::isBadCapture() const { return phase == PH_BAD_CAPTURES; }
bool MovePicker::isBadCapture() const { return phase == PH_BAD_CAPTURES; }
-/// Constructor for the MovePicker class. Apart from the position for which
-/// it is asked to pick legal moves, MovePicker also wants some information
+/// Constructor for the MovePicker class. As arguments we pass information
/// to help it to return the presumably good moves first, to decide which
/// moves to return (in the quiescence search, for instance, we only want to
/// search captures, promotions and some checks) and about how important good
/// to help it to return the presumably good moves first, to decide which
/// moves to return (in the quiescence search, for instance, we only want to
/// search captures, promotions and some checks) and about how important good
}
/// MovePicker::get_next_move() is the most important method of the MovePicker
}
/// MovePicker::get_next_move() is the most important method of the MovePicker
-/// class. It returns a new legal move every time it is called, until there
+/// class. It returns a new pseudo legal move every time it is called, until there
/// are no more moves left. It picks the move with the biggest score from a list
/// of generated moves taking care not to return the tt move if has already been
/// searched previously. Note that this function is not thread safe so should be
/// are no more moves left. It picks the move with the biggest score from a list
/// of generated moves taking care not to return the tt move if has already been
/// searched previously. Note that this function is not thread safe so should be
return move;
// Losing capture, move it to the tail of the array, note
return move;
// Losing capture, move it to the tail of the array, note
- // that move has now been already checked for legality.
+ // that move has now been already checked for pseudo legality.
(--badCaptures)->move = move;
badCaptures->score = seeValue;
}
(--badCaptures)->move = move;
badCaptures->score = seeValue;
}
case PH_QCHECKS:
move = (curMove++)->move;
case PH_QCHECKS:
move = (curMove++)->move;
- if ( move != ttMoves[0].move)
+ if (move != ttMoves[0].move)
-/// MovePicker is a class which is used to pick one legal move at a time from
-/// the current position. It is initialized with a Position object and a few
+/// MovePicker is a class which is used to pick one pseudo legal move at a time
+/// from the current position. It is initialized with a Position object and a few
/// moves we have reason to believe are good. The most important method is
/// moves we have reason to believe are good. The most important method is
-/// MovePicker::get_next_move(), which returns a new legal move each time it
-/// is called, until there are no legal moves left, when MOVE_NONE is returned.
+/// MovePicker::get_next_move(), which returns a new pseudo legal move each time
+/// it is called, until there are no moves left, when MOVE_NONE is returned.
/// In order to improve the efficiency of the alpha beta algorithm, MovePicker
/// attempts to return the moves which are most likely to get a cut-off first.
/// In order to improve the efficiency of the alpha beta algorithm, MovePicker
/// attempts to return the moves which are most likely to get a cut-off first.
-/// Position::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.
+/// Position::move_is_pl_slow() takes a position and a move and tests whether
+/// the move is pseudo legal. This version is not very fast and should be used
+/// only in non time-critical paths.
-bool Position::move_is_pl_full(const Move m) const {
+bool Position::move_is_pl_slow(const Move m) const {
MoveStack mlist[MAX_MOVES];
MoveStack mlist[MAX_MOVES];
- MoveStack *cur, *last = generate<MV_PSEUDO_LEGAL>(*this, mlist);
- for (cur = mlist; cur != last; cur++)
+ last = in_check() ? generate<MV_EVASION>(*this, mlist)
+ : generate<MV_NON_EVASION>(*this, mlist);
+
+ for (cur = mlist; cur != last; cur++)
if (cur->move == m)
return true;
if (cur->move == m)
return true;
-/// Fast version of Position::move_is_legal() that takes a position a move and
-/// a bitboard of pinned pieces as input, and tests whether the move is legal.
+/// Fast version of Position::move_is_pl() that takes a position a move and a
+/// bitboard of pinned pieces as input, and tests whether the move is pseudo legal.
bool Position::move_is_pl(const Move m) const {
bool Position::move_is_pl(const Move m) const {
// Use a slower but simpler function for uncommon cases
if (move_is_special(m))
// Use a slower but simpler function for uncommon cases
if (move_is_special(m))
- return move_is_pl_full(m);
+ return move_is_pl_slow(m);
// Is not a promotion, so promotion piece must be empty
if (move_promotion_piece(m) - 2 != PIECE_TYPE_NONE)
// Is not a promotion, so promotion piece must be empty
if (move_promotion_piece(m) - 2 != PIECE_TYPE_NONE)
// Properties of moves
bool pl_move_is_legal(Move m, Bitboard pinned) const;
// Properties of moves
bool pl_move_is_legal(Move m, Bitboard pinned) const;
- bool move_is_pl_full(const Move m) const;
bool move_is_pl(const Move m) const;
bool move_gives_check(Move m) const;
bool move_gives_check(Move m, const CheckInfo& ci) const;
bool move_is_pl(const Move m) const;
bool move_gives_check(Move m) const;
bool move_gives_check(Move m, const CheckInfo& ci) const;
void do_allow_oo(Color c);
void do_allow_ooo(Color c);
bool set_castling_rights(char token);
void do_allow_oo(Color c);
void do_allow_ooo(Color c);
bool set_castling_rights(char token);
+ bool move_is_pl_slow(const Move m) const;
// Helper functions for doing and undoing moves
void do_capture_move(Key& key, PieceType capture, Color them, Square to, bool ep);
// Helper functions for doing and undoing moves
void do_capture_move(Key& key, PieceType capture, Color them, Square to, bool ep);