From 4c3a000211bea046dd9506bae748576ecf6368fa Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Tue, 24 May 2011 09:07:20 +0200 Subject: [PATCH] A bit of reformatting after previous series And some documentation update. No functional change. Signed-off-by: Marco Costalba --- src/movegen.cpp | 14 +++----------- src/movegen.h | 3 +-- src/movepick.cpp | 9 ++++----- src/movepick.h | 8 ++++---- src/position.cpp | 21 ++++++++++++--------- src/position.h | 2 +- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index 297b51ff..e1e6a54b 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -304,16 +304,7 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { } -/// generate computes a complete list of legal -/// or pseudo-legal moves in the current position. -template<> -MoveStack* generate(const Position& pos, MoveStack* mlist) { - - assert(pos.is_ok()); - - return pos.in_check() ? generate(pos, mlist) - : generate(pos, mlist); -} +/// generate computes a complete list of legal moves in the current position template<> MoveStack* generate(const Position& pos, MoveStack* mlist) { @@ -323,7 +314,8 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { MoveStack *last, *cur = mlist; Bitboard pinned = pos.pinned_pieces(pos.side_to_move()); - last = generate(pos, mlist); + last = pos.in_check() ? generate(pos, mlist) + : generate(pos, mlist); // Remove illegal moves from the list while (cur != last) diff --git a/src/movegen.h b/src/movegen.h index 6a04248a..580ca2e7 100644 --- a/src/movegen.h +++ b/src/movegen.h @@ -30,8 +30,7 @@ enum MoveType { MV_NON_CAPTURE_CHECK, MV_EVASION, MV_NON_EVASION, - MV_LEGAL, - MV_PSEUDO_LEGAL + MV_LEGAL }; template diff --git a/src/movepick.cpp b/src/movepick.cpp index 2f9cd146..793a90da 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -48,8 +48,7 @@ namespace { 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 @@ -251,7 +250,7 @@ void MovePicker::score_evasions() { } /// 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 @@ -286,7 +285,7 @@ Move MovePicker::get_next_move() { 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; } @@ -328,7 +327,7 @@ Move MovePicker::get_next_move() { case PH_QCHECKS: move = (curMove++)->move; - if ( move != ttMoves[0].move) + if (move != ttMoves[0].move) return move; break; diff --git a/src/movepick.h b/src/movepick.h index 5455a3df..fdbd834e 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -27,11 +27,11 @@ struct SearchStack; -/// 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 -/// 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. diff --git a/src/position.cpp b/src/position.cpp index 4c925f5b..867a7f0b 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -624,16 +624,19 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { } -/// 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 *cur, *last = generate(*this, mlist); + MoveStack *cur, *last; - for (cur = mlist; cur != last; cur++) + last = in_check() ? generate(*this, mlist) + : generate(*this, mlist); + + for (cur = mlist; cur != last; cur++) if (cur->move == m) return true; @@ -641,8 +644,8 @@ bool Position::move_is_pl_full(const Move m) const { } -/// 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 { @@ -656,7 +659,7 @@ bool Position::move_is_pl(const Move m) const { // 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) diff --git a/src/position.h b/src/position.h index 496b7b9d..af1e981c 100644 --- a/src/position.h +++ b/src/position.h @@ -186,7 +186,6 @@ public: // 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; @@ -260,6 +259,7 @@ private: 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); -- 2.39.2