[gnome-chess] Add ChessGame.can_claim_draw()



commit b1128fa66b44ff7c305f7a52b4372f5843169569
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Apr 8 22:13:11 2014 -0500

    Add ChessGame.can_claim_draw()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727789

 lib/chess-game.vala   |   20 ++++++++++++--------
 lib/chess-player.vala |    6 +++---
 src/gnome-chess.vala  |    2 +-
 3 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/lib/chess-game.vala b/lib/chess-game.vala
index ab5603e..08c5823 100644
--- a/lib/chess-game.vala
+++ b/lib/chess-game.vala
@@ -212,19 +212,23 @@ public class ChessGame
         return true;
     }
 
-    private bool claim_draw_cb (ChessPlayer player)
+    private bool is_fifty_move_rule_fulfilled ()
     {
-        if (!is_started)
-            return false;
+        /* Fifty moves per player without capture or pawn advancement */
+        return current_state.halfmove_clock >= 100;
+    }
+
+    public bool can_claim_draw ()
+    {
+        return is_fifty_move_rule_fulfilled () || is_three_fold_repeat ();
+    }
 
-        if (current_state.halfmove_clock >= 100)
+    private void claim_draw_cb ()
+    {
+        if (is_fifty_move_rule_fulfilled ())
             stop (ChessResult.DRAW, ChessRule.FIFTY_MOVES);
         else if (is_three_fold_repeat ())
             stop (ChessResult.DRAW, ChessRule.THREE_FOLD_REPETITION);
-        else
-            return false;
-
-        return true;
     }
 
     public void start ()
diff --git a/lib/chess-player.vala b/lib/chess-player.vala
index e9966c1..0b19ecc 100644
--- a/lib/chess-player.vala
+++ b/lib/chess-player.vala
@@ -22,7 +22,7 @@ public class ChessPlayer : Object
     public signal bool do_move (string move, bool apply);
     public signal void do_undo ();
     public signal bool do_resign ();
-    public signal bool do_claim_draw ();
+    public signal void do_claim_draw ();
 
     private bool _local_human = false;
     public bool local_human
@@ -80,8 +80,8 @@ public class ChessPlayer : Object
         return do_resign ();
     }
 
-    public bool claim_draw ()
+    public void claim_draw ()
     {
-        return do_claim_draw ();
+        do_claim_draw ();
     }
 }
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 9da5415..84e8852 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -700,7 +700,7 @@ public class Application : Gtk.Application
 
     private void engine_claim_draw_cb (ChessEngine engine)
     {
-        if (!opponent.claim_draw ())
+        if (!game.can_claim_draw ())
             game.stop (ChessResult.BUG, ChessRule.BUG);
     }
 


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