[gnome-chess] gnome-chess currently disables undo functionality when a game has ended. This commit keeps the undo
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] gnome-chess currently disables undo functionality when a game has ended. This commit keeps the undo
- Date: Sun, 18 Oct 2020 14:31:30 +0000 (UTC)
commit 0ab9614e13f3df1c5ca24b6e83474bac7b616a38
Author: Amandeep Singh <newtodisworld gmail com>
Date: Wed Oct 14 13:20:34 2020 +0530
gnome-chess currently disables undo functionality when a game has ended.
This commit keeps the undo button enabled even after end of a game.
User can now undo a move even after a checkmate or a draw.
Closes #44
lib/chess-game.vala | 11 ++++++++++-
src/chess-engine-cecp.vala | 5 -----
src/gnome-chess.vala | 16 ++++------------
3 files changed, 14 insertions(+), 18 deletions(-)
---
diff --git a/lib/chess-game.vala b/lib/chess-game.vala
index 528c9f5..d962238 100644
--- a/lib/chess-game.vala
+++ b/lib/chess-game.vala
@@ -216,8 +216,17 @@ public class ChessGame : Object
if (move_stack.next == null)
return;
- /* Pop off the move state and notify */
+ /* Pop off the move state */
move_stack.remove_link (move_stack);
+
+ /* Restart the game if undo was done after end of the game */
+ if (result != ChessResult.IN_PROGRESS)
+ {
+ result = ChessResult.IN_PROGRESS;
+ start ();
+ }
+
+ /* Notify */
undo ();
}
diff --git a/src/chess-engine-cecp.vala b/src/chess-engine-cecp.vala
index fe032c9..4e9b5b0 100644
--- a/src/chess-engine-cecp.vala
+++ b/src/chess-engine-cecp.vala
@@ -78,11 +78,6 @@ public class ChessEngineCECP : ChessEngine
stop ();
error ();
}
- else if (line.has_prefix ("1-0") || line.has_prefix ("0-1"))
- {
- /* The engine thinks the game is over and will not play on. */
- stop ();
- }
else if (line == "game is a draw" ||
line == "draw" ||
line == "Draw" ||
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 3e6cbfe..ca586e9 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -1163,6 +1163,7 @@ Copyright © 2015–2016 Sahil Sareen""";
/* Remove from the PGN game */
pgn_game.moves.remove_link (pgn_game.moves.last ());
+ pgn_game.result = PGNGame.RESULT_IN_PROGRESS;
/* Remove from the history */
var model = (Gtk.ListStore) history_combo.model;
@@ -1255,6 +1256,7 @@ Copyright © 2015–2016 Sahil Sareen""";
/* Window title on Black's turn if Black is a computer */
headerbar.set_title (_("Black is Thinking…"));
}
+ headerbar.set_subtitle (null);
}
private void update_pause_resume_button ()
@@ -1281,7 +1283,6 @@ Copyright © 2015–2016 Sahil Sareen""";
private void game_end_cb ()
{
disable_window_action (RESIGN_ACTION_NAME);
- disable_window_action (UNDO_MOVE_ACTION_NAME);
disable_window_action (PAUSE_RESUME_ACTION_NAME);
/* In case of engine desync before the first move, or after undo */
@@ -1289,9 +1290,6 @@ Copyright © 2015–2016 Sahil Sareen""";
game_needs_saving = false;
- if (opponent_engine != null)
- opponent_engine.stop ();
-
string title = "";
switch (game.result)
{
@@ -1502,15 +1500,12 @@ Copyright © 2015–2016 Sahil Sareen""";
var response = dialog.run ();
dialog.destroy ();
+ game.unpause ();
if (response == ResponseType.ACCEPT)
{
game.current_player.claim_draw ();
}
- else
- {
- game.unpause ();
- }
}
public void new_game_cb ()
@@ -1540,6 +1535,7 @@ Copyright © 2015–2016 Sahil Sareen""";
var response = dialog.run ();
dialog.destroy ();
+ game.unpause ();
if (response == ResponseType.ACCEPT)
{
@@ -1548,10 +1544,6 @@ Copyright © 2015–2016 Sahil Sareen""";
else
game.current_player.resign ();
}
- else
- {
- game.unpause ();
- }
}
public void undo_move_cb ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]