1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

A bit of reformatting after previous series

And some documentation update.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-05-24 09:07:20 +02:00
parent 9884573561
commit 4c3a000211
6 changed files with 25 additions and 32 deletions

View file

@ -304,16 +304,7 @@ MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
} }
/// generate<MV_LEGAL / MV_PSEUDO_LEGAL> computes a complete list of legal /// generate<MV_LEGAL> computes a complete list of legal moves in the current position
/// 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);
}
template<> template<>
MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) { MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {
@ -323,7 +314,8 @@ MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {
MoveStack *last, *cur = mlist; MoveStack *last, *cur = mlist;
Bitboard pinned = pos.pinned_pieces(pos.side_to_move()); 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 // Remove illegal moves from the list
while (cur != last) while (cur != last)

View file

@ -30,8 +30,7 @@ enum MoveType {
MV_NON_CAPTURE_CHECK, MV_NON_CAPTURE_CHECK,
MV_EVASION, MV_EVASION,
MV_NON_EVASION, MV_NON_EVASION,
MV_LEGAL, MV_LEGAL
MV_PSEUDO_LEGAL
}; };
template<MoveType> template<MoveType>

View file

@ -48,8 +48,7 @@ namespace {
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 /// Constructor for the MovePicker class. As arguments we pass information
/// it is asked to pick legal moves, MovePicker also wants some information
/// to help it to return the presumably good moves first, to decide which /// 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 /// moves to return (in the quiescence search, for instance, we only want to
/// search captures, promotions and some checks) and about how important good /// 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 /// 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 /// 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 /// 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 /// searched previously. Note that this function is not thread safe so should be
@ -286,7 +285,7 @@ Move MovePicker::get_next_move() {
return move; return move;
// Losing capture, move it to the tail of the array, note // 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)->move = move;
badCaptures->score = seeValue; badCaptures->score = seeValue;
} }
@ -328,7 +327,7 @@ Move MovePicker::get_next_move() {
case PH_QCHECKS: case PH_QCHECKS:
move = (curMove++)->move; move = (curMove++)->move;
if ( move != ttMoves[0].move) if (move != ttMoves[0].move)
return move; return move;
break; break;

View file

@ -27,11 +27,11 @@
struct SearchStack; struct SearchStack;
/// MovePicker is a class which is used to pick one legal move at a time from /// MovePicker is a class which is used to pick one pseudo legal move at a time
/// the current position. It is initialized with a Position object and a few /// 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 /// MovePicker::get_next_move(), which returns a new pseudo legal move each time
/// is called, until there are no legal moves left, when MOVE_NONE is returned. /// 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 /// 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. /// attempts to return the moves which are most likely to get a cut-off first.

View file

@ -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) /// Position::move_is_pl_slow() takes a position and a move and tests whether
/// move and tests whether the move is legal. This version is not very fast and /// the move is pseudo legal. This version is not very fast and should be used
/// should be used only in non time-critical paths. /// 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); MoveStack *cur, *last;
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) if (cur->move == m)
return true; 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 /// Fast version of Position::move_is_pl() that takes a position a move and a
/// a bitboard of pinned pieces as input, and tests whether the move is legal. /// 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 {
@ -656,7 +659,7 @@ bool Position::move_is_pl(const Move m) const {
// Use a slower but simpler function for uncommon cases // Use a slower but simpler function for uncommon cases
if (move_is_special(m)) 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 // Is not a promotion, so promotion piece must be empty
if (move_promotion_piece(m) - 2 != PIECE_TYPE_NONE) if (move_promotion_piece(m) - 2 != PIECE_TYPE_NONE)

View file

@ -186,7 +186,6 @@ public:
// Properties of moves // Properties of moves
bool pl_move_is_legal(Move m, Bitboard pinned) const; 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_is_pl(const Move m) const;
bool move_gives_check(Move m) const; bool move_gives_check(Move m) const;
bool move_gives_check(Move m, const CheckInfo& ci) 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_oo(Color c);
void do_allow_ooo(Color c); void do_allow_ooo(Color c);
bool set_castling_rights(char token); bool set_castling_rights(char token);
bool move_is_pl_slow(const Move m) const;
// Helper functions for doing and undoing moves // Helper functions for doing and undoing moves
void do_capture_move(Key& key, PieceType capture, Color them, Square to, bool ep); void do_capture_move(Key& key, PieceType capture, Color them, Square to, bool ep);