]> git.sesse.net Git - stockfish/commitdiff
Simplify Position::is_mate()
authorMarco Costalba <mcostalba@gmail.com>
Sun, 19 Apr 2009 15:44:12 +0000 (16:44 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 19 Apr 2009 16:13:04 +0000 (17:13 +0100)
Should be a bit faster too.

No functional change.

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

index 063233111dea59066bffb702c3597ec31ca7b87f..3e72c0e9c88c1185f6eb1a03e44fa60cd2a1a160 100644 (file)
@@ -1867,21 +1867,6 @@ Value Position::compute_non_pawn_material(Color c) const {
 }
 
 
-/// Position::is_mate() returns true or false depending on whether the
-/// side to move is checkmated. Note that this function is currently very
-/// slow, and shouldn't be used frequently inside the search.
-
-bool Position::is_mate() const {
-
-  if (is_check())
-  {
-      MovePicker mp = MovePicker(*this, false, MOVE_NONE, EmptySearchStack, Depth(0));
-      return mp.get_next_move() == MOVE_NONE;
-  }
-  return false;
-}
-
-
 /// Position::is_draw() tests whether the position is drawn by material,
 /// repetition, or the 50 moves rule. It does not detect stalemates, this
 /// must be done by the search.
@@ -1906,6 +1891,17 @@ bool Position::is_draw() const {
 }
 
 
+/// Position::is_mate() returns true or false depending on whether the
+/// side to move is checkmated.
+
+bool Position::is_mate() const {
+
+  MoveStack moves[256];
+
+  return is_check() && !generate_evasions(*this, moves, pinned_pieces(sideToMove));
+}
+
+
 /// Position::has_mate_threat() tests whether a given color has a mate in one
 /// from the current position. This function is quite slow, but it doesn't
 /// matter, because it is currently only called from PV nodes, which are rare.