]> git.sesse.net Git - stockfish/commitdiff
Change move_is_ok() and square_is_ok() in something useful
authorMarco Costalba <mcostalba@gmail.com>
Thu, 6 Jan 2011 09:32:27 +0000 (10:32 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 6 Jan 2011 09:55:48 +0000 (10:55 +0100)
As is defined now is always true, tested with:

  for (long i=-1000000; i < 1000000; i++)
      if (!move_is_ok(Move(i)))
          exit(0);

Reason is that move_from() and move_to() already truncate the
input value to something in the range [0, 63] that is always
a possible square.

So change definition to something useful.

The same applies also to square_is_ok()

No functional change.

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

index 2a18c1c4eb10eb342d6cf3520e40a4038229146c..cb6b5dfdc3bd80ad27f6e3e1dc100103ca86c69d 100644 (file)
@@ -135,7 +135,7 @@ const std::string move_to_uci(Move move, bool chess960) {
 }
 
 
-/// Overload the << operator, to make it easier to print moves.
+/// Overload the << operator, to make it easier to print moves
 
 std::ostream& operator << (std::ostream& os, Move m) {
 
@@ -144,9 +144,9 @@ std::ostream& operator << (std::ostream& os, Move m) {
 }
 
 
-/// move_is_ok(), for debugging.
+/// move_is_ok(), for debugging
 
 bool move_is_ok(Move m) {
 
-  return square_is_ok(move_from(m)) && square_is_ok(move_to(m));
+  return move_from(m) != move_to(m); // Catches also MOVE_NONE
 }
index c4ed9dd81bcaf0e3cb5e1968fa5b4f3053307d9a..d06e381a761c819a6b93c88f9093e532a73b7534 100644 (file)
@@ -207,5 +207,4 @@ extern Move move_from_uci(const Position& pos, const std::string &str);
 extern const std::string move_to_uci(Move m, bool chess960);
 extern bool move_is_ok(Move m);
 
-
 #endif // !defined(MOVE_H_INCLUDED)
index f89c72eefe6b770075594b7092ca1b42d1ce9185..46456d0677c88fed74609a2a9654e68245ba830a 100644 (file)
@@ -177,7 +177,7 @@ inline bool rank_is_ok(Rank r) {
 }
 
 inline bool square_is_ok(Square s) {
-  return file_is_ok(square_file(s)) && rank_is_ok(square_rank(s));
+  return s >= SQ_A1 && s <= SQ_H8;
 }
 
 #endif // !defined(SQUARE_H_INCLUDED)