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:
parent
95d9687d95
commit
155bed18f5
4 changed files with 19 additions and 24 deletions
14
src/move.cpp
14
src/move.cpp
|
@ -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
|
||||
/// 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.
|
||||
|
||||
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(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));
|
||||
string san;
|
||||
|
||||
if (m == MOVE_NONE)
|
||||
return "(none)";
|
||||
|
||||
if (m == MOVE_NULL)
|
||||
return "(null)";
|
||||
|
||||
if (move_is_castle(m))
|
||||
san = (move_to(m) < move_from(m) ? "O-O-O" : "O-O");
|
||||
else
|
||||
|
|
|
@ -36,6 +36,8 @@ enum MoveType {
|
|||
template<MoveType>
|
||||
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>
|
||||
struct MoveList {
|
||||
|
||||
|
|
|
@ -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
|
||||
/// is pseudo legal. This version is not very fast and should be used
|
||||
/// only in non time-critical paths.
|
||||
/// Position::move_is_legal() takes a move and tests whether the move
|
||||
/// is legal. This version is not very fast and should be used only
|
||||
/// 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];
|
||||
MoveStack *cur, *last;
|
||||
|
||||
last = in_check() ? generate<MV_EVASION>(*this, mlist)
|
||||
: generate<MV_NON_EVASION>(*this, mlist);
|
||||
|
||||
for (cur = mlist; cur != last; cur++)
|
||||
if (cur->move == m)
|
||||
for (MoveList<MV_LEGAL> ml(*this); !ml.end(); ++ml)
|
||||
if (ml.move() == m)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -580,7 +574,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_slow(m);
|
||||
return move_is_legal(m);
|
||||
|
||||
// Is not a promotion, so promotion piece must be empty
|
||||
if (promotion_piece_type(m) - 2 != PIECE_TYPE_NONE)
|
||||
|
|
|
@ -221,7 +221,7 @@ private:
|
|||
void put_piece(Piece p, Square s);
|
||||
void set_castle(int f, Square ksq, Square rsq);
|
||||
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
|
||||
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 {
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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"
|
||||
assert(move_is_ok(m));
|
||||
return (!square_is_empty(move_to(m)) && !move_is_castle(m)) || move_is_ep(m);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue