mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 01:03:09 +00:00
Retire Position::move_is_legal()
Use the new contains() method of struct MoveList No functional change.
This commit is contained in:
parent
423c6d8a8a
commit
3b49aeb4f2
5 changed files with 10 additions and 19 deletions
|
@ -46,6 +46,10 @@ struct MoveList {
|
||||||
bool end() const { return cur == last; }
|
bool end() const { return cur == last; }
|
||||||
Move move() const { return cur->move; }
|
Move move() const { return cur->move; }
|
||||||
size_t size() const { return last - mlist; }
|
size_t size() const { return last - mlist; }
|
||||||
|
bool contains(Move m) const {
|
||||||
|
for (const MoveStack* it(mlist) ; it != last; ++it) if (it->move == m) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MoveStack mlist[MAX_MOVES];
|
MoveStack mlist[MAX_MOVES];
|
||||||
|
|
|
@ -108,7 +108,7 @@ const string move_to_san(Position& pos, Move m) {
|
||||||
if (m == MOVE_NULL)
|
if (m == MOVE_NULL)
|
||||||
return "(null)";
|
return "(null)";
|
||||||
|
|
||||||
assert(pos.move_is_legal(m));
|
assert(MoveList<LEGAL>(pos).contains(m));
|
||||||
|
|
||||||
Bitboard attackers;
|
Bitboard attackers;
|
||||||
bool ambiguousMove, ambiguousFile, ambiguousRank;
|
bool ambiguousMove, ambiguousFile, ambiguousRank;
|
||||||
|
|
|
@ -521,20 +521,6 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::move_is_legal() takes a random 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_legal(const Move m) const {
|
|
||||||
|
|
||||||
for (MoveList<LEGAL> ml(*this); !ml.end(); ++ml)
|
|
||||||
if (ml.move() == m)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Position::is_pseudo_legal() takes a random move and tests whether the move
|
/// Position::is_pseudo_legal() takes a random move and tests whether the move
|
||||||
/// is pseudo legal. It is used to validate moves from TT that can be corrupted
|
/// is pseudo legal. It is used to validate moves from TT that can be corrupted
|
||||||
/// due to SMP concurrent access or hash position key aliasing.
|
/// due to SMP concurrent access or hash position key aliasing.
|
||||||
|
@ -548,7 +534,7 @@ bool Position::is_pseudo_legal(const Move m) const {
|
||||||
|
|
||||||
// Use a slower but simpler function for uncommon cases
|
// Use a slower but simpler function for uncommon cases
|
||||||
if (type_of(m) != NORMAL)
|
if (type_of(m) != NORMAL)
|
||||||
return move_is_legal(m);
|
return MoveList<LEGAL>(*this).contains(m);
|
||||||
|
|
||||||
// Is not a promotion, so promotion piece must be empty
|
// Is not a promotion, so promotion piece must be empty
|
||||||
if (promotion_type(m) - 2 != NO_PIECE_TYPE)
|
if (promotion_type(m) - 2 != NO_PIECE_TYPE)
|
||||||
|
|
|
@ -137,7 +137,6 @@ public:
|
||||||
|
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool move_gives_check(Move m, const CheckInfo& ci) const;
|
bool move_gives_check(Move m, const CheckInfo& ci) const;
|
||||||
bool move_is_legal(const Move m) const;
|
|
||||||
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
||||||
bool is_pseudo_legal(const Move m) const;
|
bool is_pseudo_legal(const Move m) const;
|
||||||
bool is_capture(Move m) const;
|
bool is_capture(Move m) const;
|
||||||
|
|
|
@ -1540,7 +1540,8 @@ void RootMove::extract_pv_from_tt(Position& pos) {
|
||||||
do {
|
do {
|
||||||
pv.push_back(m);
|
pv.push_back(m);
|
||||||
|
|
||||||
assert(pos.move_is_legal(pv[ply]));
|
assert(MoveList<LEGAL>(pos).contains(pv[ply]));
|
||||||
|
|
||||||
pos.do_move(pv[ply++], *st++);
|
pos.do_move(pv[ply++], *st++);
|
||||||
tte = TT.probe(pos.key());
|
tte = TT.probe(pos.key());
|
||||||
|
|
||||||
|
@ -1572,7 +1573,8 @@ void RootMove::insert_pv_in_tt(Position& pos) {
|
||||||
if (!tte || tte->move() != pv[ply]) // Don't overwrite correct entries
|
if (!tte || tte->move() != pv[ply]) // Don't overwrite correct entries
|
||||||
TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply]);
|
TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply]);
|
||||||
|
|
||||||
assert(pos.move_is_legal(pv[ply]));
|
assert(MoveList<LEGAL>(pos).contains(pv[ply]));
|
||||||
|
|
||||||
pos.do_move(pv[ply++], *st++);
|
pos.do_move(pv[ply++], *st++);
|
||||||
|
|
||||||
} while (pv[ply] != MOVE_NONE);
|
} while (pv[ply] != MOVE_NONE);
|
||||||
|
|
Loading…
Add table
Reference in a new issue