]> git.sesse.net Git - stockfish/commitdiff
Retire Position::move_is_legal()
authorMarco Costalba <mcostalba@gmail.com>
Tue, 25 Dec 2012 10:40:28 +0000 (11:40 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 25 Dec 2012 10:51:08 +0000 (11:51 +0100)
Use the new contains() method of struct MoveList

No functional change.

src/movegen.h
src/notation.cpp
src/position.cpp
src/position.h
src/search.cpp

index 84d5d35ef70b07789f98e4149de0cf4ae3f95e41..9f45e250912602003c366f1942412edb56cbc1ff 100644 (file)
@@ -46,6 +46,10 @@ struct MoveList {
   bool end() const { return cur == last; }
   Move move() const { return cur->move; }
   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:
   MoveStack mlist[MAX_MOVES];
index 15661eec725ab7c7b788f51cc825cb9e201a57f1..85b0abdd2914e6c268da8408cc888de0828f3b5b 100644 (file)
@@ -108,7 +108,7 @@ const string move_to_san(Position& pos, Move m) {
   if (m == MOVE_NULL)
       return "(null)";
 
-  assert(pos.move_is_legal(m));
+  assert(MoveList<LEGAL>(pos).contains(m));
 
   Bitboard attackers;
   bool ambiguousMove, ambiguousFile, ambiguousRank;
index 045b10cab7c276b8fc3806a09c4751c33fdf2523..ef5fd97091cc4f0f478b41954090ba8e72a1799f 100644 (file)
@@ -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
 /// 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.
@@ -548,7 +534,7 @@ bool Position::is_pseudo_legal(const Move m) const {
 
   // Use a slower but simpler function for uncommon cases
   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
   if (promotion_type(m) - 2 != NO_PIECE_TYPE)
index 738fe8c9968272de24ec578a636eba5c032d37df..e575c3ef9a7127cec8e95d73f75ee0e12d112e12 100644 (file)
@@ -137,7 +137,6 @@ public:
 
   // Properties of moves
   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 is_pseudo_legal(const Move m) const;
   bool is_capture(Move m) const;
index 292faf0412a35e01f18320b275fed883c5efe56b..f7d3a9fd20f0be04863b1447a1ad622cc91f0fa6 100644 (file)
@@ -1540,7 +1540,8 @@ void RootMove::extract_pv_from_tt(Position& pos) {
   do {
       pv.push_back(m);
 
-      assert(pos.move_is_legal(pv[ply]));
+      assert(MoveList<LEGAL>(pos).contains(pv[ply]));
+
       pos.do_move(pv[ply++], *st++);
       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
           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++);
 
   } while (pv[ply] != MOVE_NONE);