1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 11:39:15 +00:00

Simplify Position::is_mate()

Should be a bit faster too.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-04-19 16:44:12 +01:00
parent a52ab2afbf
commit 2acc89c6e8

View 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, /// Position::is_draw() tests whether the position is drawn by material,
/// repetition, or the 50 moves rule. It does not detect stalemates, this /// repetition, or the 50 moves rule. It does not detect stalemates, this
/// must be done by the search. /// 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 /// 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 /// 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. /// matter, because it is currently only called from PV nodes, which are rare.