1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 00:33:09 +00:00

Use MoveList also in Position::move_is_pl_slow()

And rename it in Position::move_is_legal()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-07-03 10:38:20 +01:00
parent 95d9687d95
commit 155bed18f5
4 changed files with 19 additions and 24 deletions

View file

@ -77,11 +77,17 @@ Move move_from_uci(const Position& pos, const string& str) {
/// move_to_san() takes a position and a move as input, where it is assumed /// move_to_san() takes a position and a move as input, where it is assumed
/// that the move is a legal move from the position. The return value is /// that the move is a legal move for the position. The return value is
/// a string containing the move in short algebraic notation. /// a string containing the move in short algebraic notation.
const string move_to_san(Position& pos, Move m) { const string move_to_san(Position& pos, Move m) {
if (m == MOVE_NONE)
return "(none)";
if (m == MOVE_NULL)
return "(null)";
assert(pos.is_ok()); assert(pos.is_ok());
assert(move_is_ok(m)); assert(move_is_ok(m));
@ -92,12 +98,6 @@ const string move_to_san(Position& pos, Move m) {
PieceType pt = piece_type(pos.piece_on(from)); PieceType pt = piece_type(pos.piece_on(from));
string san; string san;
if (m == MOVE_NONE)
return "(none)";
if (m == MOVE_NULL)
return "(null)";
if (move_is_castle(m)) if (move_is_castle(m))
san = (move_to(m) < move_from(m) ? "O-O-O" : "O-O"); san = (move_to(m) < move_from(m) ? "O-O-O" : "O-O");
else else

View file

@ -36,6 +36,8 @@ enum MoveType {
template<MoveType> template<MoveType>
MoveStack* generate(const Position& pos, MoveStack* mlist); MoveStack* generate(const Position& pos, MoveStack* mlist);
/// The MoveList struct is a simple wrapper around generate(), sometimes comes
/// handy to use this class instead of the low level generate() function.
template<MoveType T> template<MoveType T>
struct MoveList { struct MoveList {

View file

@ -545,20 +545,14 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
} }
/// Position::move_is_pl_slow() takes a move and tests whether the move /// Position::move_is_legal() takes a move and tests whether the move
/// is pseudo legal. This version is not very fast and should be used /// is legal. This version is not very fast and should be used only
/// only in non time-critical paths. /// in non time-critical paths.
bool Position::move_is_pl_slow(const Move m) const { bool Position::move_is_legal(const Move m) const {
MoveStack mlist[MAX_MOVES]; for (MoveList<MV_LEGAL> ml(*this); !ml.end(); ++ml)
MoveStack *cur, *last; if (ml.move() == m)
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; return true;
return false; return false;
@ -580,7 +574,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_slow(m); return move_is_legal(m);
// Is not a promotion, so promotion piece must be empty // Is not a promotion, so promotion piece must be empty
if (promotion_piece_type(m) - 2 != PIECE_TYPE_NONE) if (promotion_piece_type(m) - 2 != PIECE_TYPE_NONE)

View file

@ -221,7 +221,7 @@ private:
void put_piece(Piece p, Square s); void put_piece(Piece p, Square s);
void set_castle(int f, Square ksq, Square rsq); void set_castle(int f, Square ksq, Square rsq);
void set_castling_rights(char token); void set_castling_rights(char token);
bool move_is_pl_slow(const Move m) const; bool move_is_legal(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);
@ -449,15 +449,14 @@ inline bool Position::is_chess960() const {
inline bool Position::move_is_capture_or_promotion(Move m) const { inline bool Position::move_is_capture_or_promotion(Move m) const {
assert(m != MOVE_NONE && m != MOVE_NULL); assert(move_is_ok(m));
return move_is_special(m) ? !move_is_castle(m) : !square_is_empty(move_to(m)); return move_is_special(m) ? !move_is_castle(m) : !square_is_empty(move_to(m));
} }
inline bool Position::move_is_capture(Move m) const { inline bool Position::move_is_capture(Move m) const {
assert(m != MOVE_NONE && m != MOVE_NULL);
// Note that castle is coded as "king captures the rook" // Note that castle is coded as "king captures the rook"
assert(move_is_ok(m));
return (!square_is_empty(move_to(m)) && !move_is_castle(m)) || move_is_ep(m); return (!square_is_empty(move_to(m)) && !move_is_castle(m)) || move_is_ep(m);
} }