From: Marco Costalba Date: Sun, 19 Apr 2009 15:44:12 +0000 (+0100) Subject: Simplify Position::is_mate() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=2acc89c6e86cbf3b0bd42b4db2c66a925501bb0a;ds=sidebyside Simplify Position::is_mate() Should be a bit faster too. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/position.cpp b/src/position.cpp index 06323311..3e72c0e9 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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.