Fix claim draw dialog appearing for moves through history

Using the history viewer should not trigger the claim draw dialog. I
noticed this because there's a big warning comment in game_turn_cb()
saying to not use it for anything related to the game itself, yet here
it was.

Note I add one additional check here, to mave sure the game has not
ended before telling the engine to move.

Note also that this makes every move 0.1s slower than before... that
seems fine.
This commit is contained in:
Michael Catanzaro 2018-04-24 12:09:20 -05:00
parent 384ebe0120
commit be944e49cc

View file

@ -874,12 +874,6 @@ Copyright © 20152016 Sahil Sareen""";
if (game.clock != null)
enable_window_action (PAUSE_RESUME_ACTION_NAME);
/* FIXME: This looks like the wrong place for this, as per the
* warning comment just above.
*/
if (game.can_claim_draw ())
present_claim_draw_dialog ();
}
private void set_move_text (Gtk.TreeIter iter, ChessMove move)
@ -1127,13 +1121,23 @@ Copyright © 20152016 Sahil Sareen""";
view.queue_draw ();
if (opponent_engine != null)
{
opponent_engine.report_move (move);
/* Remaining work goes in a timeout to give the game widget a chance to
* redraw first, so the pieces are shown to move before displaying the
* claim draw dialog. */
Timeout.add(100, () => {
if (game.can_claim_draw ())
present_claim_draw_dialog ();
if (move.piece.color != opponent.color && !starting)
opponent_engine.move ();
}
if (opponent_engine != null)
{
opponent_engine.report_move (move);
if (move.piece.color != opponent.color && !starting && game.is_started)
opponent_engine.move ();
}
return Source.REMOVE;
});
}
private void game_undo_cb (ChessGame game)