[gnome-chess] Handle draw offers from engines
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Handle draw offers from engines
- Date: Sun, 25 Aug 2013 17:50:37 +0000 (UTC)
commit e7b0c9dfa57e121fcbf05d0cc4eef4eb072dd011
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Aug 25 12:49:23 2013 -0500
Handle draw offers from engines
This is essential because an engine will likely refuse to play on if it
claims a valid draw and we ignore it.
https://bugzilla.gnome.org/show_bug.cgi?id=705011
src/chess-engine-cecp.vala | 8 ++++++++
src/chess-engine.vala | 2 ++
src/gnome-chess.vala | 23 +++++++++++++++++++++++
3 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/chess-engine-cecp.vala b/src/chess-engine-cecp.vala
index 74ebf69..53d879a 100644
--- a/src/chess-engine-cecp.vala
+++ b/src/chess-engine-cecp.vala
@@ -73,8 +73,16 @@ public class ChessEngineCECP : ChessEngine
{
resigned ();
}
+ else if (line == "game is a draw" ||
+ line == "draw" ||
+ line == "Draw" ||
+ line.has_prefix ("1/2-1/2"))
+ {
+ claim_draw ();
+ }
else if (line == "offer draw")
{
+ offer_draw ();
}
buffer = buffer[offset+1:buffer.length];
diff --git a/src/chess-engine.vala b/src/chess-engine.vala
index 4a05ca3..9e7b084 100644
--- a/src/chess-engine.vala
+++ b/src/chess-engine.vala
@@ -27,6 +27,8 @@ public abstract class ChessEngine : Object
public signal void resigned ();
public signal void stopped ();
public signal void error ();
+ public signal void claim_draw ();
+ public signal void offer_draw ();
private bool _ready = false;
public bool ready
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index a8b7450..2757805 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -518,6 +518,8 @@ public class Application : Gtk.Application
opponent_engine.resigned.disconnect (engine_resigned_cb);
opponent_engine.stopped.disconnect (engine_stopped_cb);
opponent_engine.error.disconnect (engine_error_cb);
+ opponent_engine.claim_draw.disconnect (engine_claim_draw_cb);
+ opponent_engine.offer_draw.disconnect (engine_offer_draw_cb);
opponent_engine = null;
}
@@ -551,6 +553,8 @@ public class Application : Gtk.Application
opponent_engine.resigned.connect (engine_resigned_cb);
opponent_engine.stopped.connect (engine_stopped_cb);
opponent_engine.error.connect (engine_error_cb);
+ opponent_engine.claim_draw.connect (engine_claim_draw_cb);
+ opponent_engine.offer_draw.connect (engine_offer_draw_cb);
opponent_engine.start ();
}
@@ -680,6 +684,25 @@ public class Application : Gtk.Application
game.stop (ChessResult.BUG, ChessRule.BUG);
}
+ private void engine_claim_draw_cb (ChessEngine engine)
+ {
+ if (!opponent.claim_draw ())
+ game.stop (ChessResult.BUG, ChessRule.BUG);
+ }
+
+ private void engine_offer_draw_cb (ChessEngine engine)
+ {
+ opponent.claim_draw ();
+
+ /*
+ * If the draw cannot be claimed, do nothing.
+ *
+ * In the future we might want to actually give the player a choice
+ * of accepting the draw, but this doesn't make much sense unless the
+ * player can also offer a draw himself.
+ */
+ }
+
private void game_start_cb (ChessGame game)
{
if (opponent_engine != null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]