]> git.sesse.net Git - stockfish/commitdiff
Use MoveList also in Position::move_is_pl_slow()
authorMarco Costalba <mcostalba@gmail.com>
Sun, 3 Jul 2011 09:38:20 +0000 (10:38 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 3 Jul 2011 10:00:28 +0000 (11:00 +0100)
And rename it in Position::move_is_legal()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/move.cpp
src/movegen.h
src/position.cpp
src/position.h

index 247f8a2abe218a3af10339bb095e84ffe97ff60a..39344aae1f76e71b2064de7e43be7f756796b027 100644 (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
-/// 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
index fdac5d0ba00856ac489b66220d3164fb0f3a005e..0c781a6ba1c3aaa576628049652ea8e00ad609d1 100644 (file)
@@ -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 {
 
index 7490953dbe3dd16a2034303bde978fe00ad4c10d..7f0e1447d08bde86e81ee24781a260509e0da54c 100644 (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
-/// 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)
index f326e4fbaa99b3fa27955abc6948398511dfb24b..37d55ed81d3e5f30b462a2accaf7b24c181129ee 100644 (file)
@@ -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);
 }