Permalink
Browse files

bugfix: safety against breaking the AI if you press undo while it's t…

…hinking
  • Loading branch information...
1 parent bf07856 commit aa6cacf2447684ea3d591b9337c7147430233626 @tomodo tomodo committed with Feb 20, 2012
Showing with 18 additions and 10 deletions.
  1. +7 −3 lib/plugins/engines/gnushogi.rb
  2. +11 −7 lib/plugins/engines/gpsshogi.rb
@@ -50,8 +50,12 @@ def on_close(data)
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
@@ -48,14 +48,18 @@ def on_close(data)
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

0 comments on commit aa6cacf

Please sign in to comment.