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
This commit is contained in:
parent
25126e77fc
commit
9324e7ca97
4 changed files with 27 additions and 4 deletions
|
@ -66,6 +66,8 @@ public class ChessEngineCECP : ChessEngine
|
|||
|
||||
if (line.has_prefix ("Illegal move: "))
|
||||
{
|
||||
stop ();
|
||||
error ();
|
||||
}
|
||||
else if (line == "resign" || line == "tellics resign")
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue