[gnome-chess] Fix "engine error" on stalemate



commit fb46a6765c013d47710441755c7335118efbadaa
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Fri Dec 4 17:46:40 2020 -0600

    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.

 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 dcf62c3..1a361d5 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -870,6 +870,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]