[gnome-chess/gnome-3-38] Fix "engine error" on stalemate



commit 7535e4e2ae15fca2919389d7c722b44124d5bac7
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Fri Dec 4 23:46:40 2020 +0000

    Fix "engine error" on stalemate
    
    When the game is stalemated, the chess engine will declare a draw. We
    then check if it can claim a draw, and if not, declare that the game has
    ended due to an engine bug. Since stalemate is not a valid reason to
    claim a draw -- it is a forced draw, not a claimable draw -- this means
    we incorrectly claim the engine is broken.
    
    Stalemate requires special handling.
    
    
    (cherry picked from commit fb46a6765c013d47710441755c7335118efbadaa)

 lib/chess-state.vala | 2 +-
 src/gnome-chess.vala | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/lib/chess-state.vala b/lib/chess-state.vala
index c5b6a1f..83dfcf8 100644
--- a/lib/chess-state.vala
+++ b/lib/chess-state.vala
@@ -642,7 +642,7 @@ public class ChessState : Object
         return true;
     }
 
-    private bool can_move (ChessPlayer player)
+    public bool can_move (ChessPlayer player)
     {
         bool have_pieces = false;
 
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 3e6cbfe..ff9ea49 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -817,6 +817,8 @@ Copyright © 2015–2016 Sahil Sareen""";
     {
         if (game.can_claim_draw ())
             opponent.claim_draw ();
+        else if (!game.current_state.can_move (game.current_state.current_player))
+            game.stop (ChessResult.DRAW, ChessRule.STALEMATE);
         else
             game.stop (ChessResult.BUG, ChessRule.BUG);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]