From aa6cacf2447684ea3d591b9337c7147430233626 Mon Sep 17 00:00:00 2001 From: Tom Oedo Date: Mon, 20 Feb 2012 17:50:07 +0000 Subject: [PATCH] bugfix: safety against breaking the AI if you press undo while it's thinking --- lib/plugins/engines/gnushogi.rb | 10 +++++++--- lib/plugins/engines/gpsshogi.rb | 18 +++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/plugins/engines/gnushogi.rb b/lib/plugins/engines/gnushogi.rb index 49f2422..6c9b73a 100644 --- a/lib/plugins/engines/gnushogi.rb +++ b/lib/plugins/engines/gnushogi.rb @@ -50,8 +50,12 @@ class GNUShogiEngine < Engine def allow_undo?(player, manager) # gnushogi waits when you tell it to undo - send_command "undo" - send_command "undo" - manager.undo(self, 2) + if @match.current_player == self + warn "Please wait until GNU Shogi moves before undoing." + else + send_command "undo" + send_command "undo" + manager.undo(self, 2) + end end end diff --git a/lib/plugins/engines/gpsshogi.rb b/lib/plugins/engines/gpsshogi.rb index d56c9b1..a0b5b86 100644 --- a/lib/plugins/engines/gpsshogi.rb +++ b/lib/plugins/engines/gpsshogi.rb @@ -48,14 +48,18 @@ class GPSShogiEngine < Engine def allow_undo?(player, manager) # gpsshogi does not wait when you tell it to undo # so we stop it from playing before calling undo - send_command "force" - send_command "undo" - send_command "undo" - if @color == :black - send_command "black" + if @match.current_player == self + warn "Please wait until GPSShogi moves before undoing." else - send_command "white" + send_command "force" + send_command "undo" + send_command "undo" + if @color == :black + send_command "black" + else + send_command "white" + end + manager.undo(self, 2) end - manager.undo(self, 2) end end -- 2.11.4.GIT