Skip to content
This repository
Browse code

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

…hinking
  • Loading branch information...
commit aa6cacf2447684ea3d591b9337c7147430233626 1 parent bf07856
tomodo tomodo authored committed
10 lib/plugins/engines/gnushogi.rb
@@ -50,8 +50,12 @@ def on_close(data)
50 50
51 51 def allow_undo?(player, manager)
52 52 # gnushogi waits when you tell it to undo
53   - send_command "undo"
54   - send_command "undo"
55   - manager.undo(self, 2)
  53 + if @match.current_player == self
  54 + warn "Please wait until GNU Shogi moves before undoing."
  55 + else
  56 + send_command "undo"
  57 + send_command "undo"
  58 + manager.undo(self, 2)
  59 + end
56 60 end
57 61 end
18 lib/plugins/engines/gpsshogi.rb
@@ -48,14 +48,18 @@ def on_close(data)
48 48 def allow_undo?(player, manager)
49 49 # gpsshogi does not wait when you tell it to undo
50 50 # so we stop it from playing before calling undo
51   - send_command "force"
52   - send_command "undo"
53   - send_command "undo"
54   - if @color == :black
55   - send_command "black"
  51 + if @match.current_player == self
  52 + warn "Please wait until GPSShogi moves before undoing."
56 53 else
57   - send_command "white"
  54 + send_command "force"
  55 + send_command "undo"
  56 + send_command "undo"
  57 + if @color == :black
  58 + send_command "black"
  59 + else
  60 + send_command "white"
  61 + end
  62 + manager.undo(self, 2)
58 63 end
59   - manager.undo(self, 2)
60 64 end
61 65 end

0 comments on commit aa6cacf

Please sign in to comment.
Something went wrong with that request. Please try again.