[gnome-chess] Report an error when something goes wrong
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Report an error when something goes wrong
- Date: Mon, 19 Aug 2013 04:07:29 +0000 (UTC)
commit 9324e7ca97d2c8680b3de06b7e171349b49a98e8
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Aug 18 22:54:05 2013 -0500
Report an error when something goes wrong
* If an engine attempts to make an illegal move
* If an engine claims we allowed an illegal move
There ought to also be a descriptive error message, but there isn't yet.
But it's way better than appearing to freeze.
https://bugzilla.gnome.org/show_bug.cgi?id=704986
src/chess-engine-cecp.vala | 2 ++
src/chess-engine.vala | 1 +
src/chess-game.vala | 8 +++++---
src/gnome-chess.vala | 20 +++++++++++++++++++-
4 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/src/chess-engine-cecp.vala b/src/chess-engine-cecp.vala
index 2eb1881..3e75183 100644
--- a/src/chess-engine-cecp.vala
+++ b/src/chess-engine-cecp.vala
@@ -66,6 +66,8 @@ public class ChessEngineCECP : ChessEngine
if (line.has_prefix ("Illegal move: "))
{
+ stop ();
+ error ();
}
else if (line == "resign" || line == "tellics resign")
{
diff --git a/src/chess-engine.vala b/src/chess-engine.vala
index ab14362..4a05ca3 100644
--- a/src/chess-engine.vala
+++ b/src/chess-engine.vala
@@ -26,6 +26,7 @@ public abstract class ChessEngine : Object
public signal void moved (string move);
public signal void resigned ();
public signal void stopped ();
+ public signal void error ();
private bool _ready = false;
public bool ready
diff --git a/src/chess-game.vala b/src/chess-game.vala
index 53d3717..2c8bb63 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -1239,7 +1239,8 @@ public enum ChessResult
IN_PROGRESS,
WHITE_WON,
BLACK_WON,
- DRAW
+ DRAW,
+ BUG
}
public enum ChessRule
@@ -1252,7 +1253,8 @@ public enum ChessRule
INSUFFICIENT_MATERIAL,
RESIGN,
ABANDONMENT,
- DEATH
+ DEATH,
+ BUG
}
public class ChessGame
@@ -1531,7 +1533,7 @@ public class ChessGame
}
}
- private void stop (ChessResult result, ChessRule rule)
+ public void stop (ChessResult result, ChessRule rule)
{
this.result = result;
this.rule = rule;
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index ba70e11..550185d 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -516,6 +516,7 @@ public class Application : Gtk.Application
opponent_engine.ready_changed.disconnect (engine_ready_cb);
opponent_engine.moved.disconnect (engine_move_cb);
opponent_engine.stopped.disconnect (engine_stopped_cb);
+ opponent_engine.error.disconnect (engine_error_cb);
opponent_engine = null;
}
@@ -547,6 +548,7 @@ public class Application : Gtk.Application
opponent_engine.ready_changed.connect (engine_ready_cb);
opponent_engine.moved.connect (engine_move_cb);
opponent_engine.stopped.connect (engine_stopped_cb);
+ opponent_engine.error.connect (engine_error_cb);
opponent_engine.start ();
}
@@ -656,7 +658,8 @@ public class Application : Gtk.Application
private void engine_move_cb (ChessEngine engine, string move)
{
- opponent.move (move);
+ if (!opponent.move (move))
+ game.stop (ChessResult.BUG, ChessRule.BUG);
}
private void engine_stopped_cb (ChessEngine engine)
@@ -664,6 +667,11 @@ public class Application : Gtk.Application
opponent.resign ();
}
+ private void engine_error_cb (ChessEngine engine)
+ {
+ game.stop (ChessResult.BUG, ChessRule.BUG);
+ }
+
private void game_start_cb (ChessGame game)
{
if (opponent_engine != null)
@@ -1005,6 +1013,11 @@ public class Application : Gtk.Application
title = _("Game is drawn");
pgn_game.result = PGNGame.RESULT_DRAW;
break;
+ case ChessResult.BUG:
+ /* Message display when the game cannot continue */
+ title = _("Oops! Something has gone wrong.");
+ /* don't set the pgn_game result; these are standards */
+ break;
default:
break;
}
@@ -1058,6 +1071,11 @@ public class Application : Gtk.Application
reason = _("One of the players has died");
pgn_game.termination = PGNGame.TERMINATE_DEATH;
break;
+ case ChessRule.BUG:
+ /* Message displayed when something goes wrong with the engine */
+ reason = _("The game cannot continue.");
+ /* Don't set pgn_game termination; these are standards*/
+ break;
}
info_title_label.set_markup ("<big><b>%s</b></big>".printf (title));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]