From bf07856cd355e1dc77284c2cb2bff8ec43b3e67c Mon Sep 17 00:00:00 2001 From: Tom Oedo Date: Mon, 20 Feb 2012 13:22:49 +0000 Subject: [PATCH] Added support for GPSShogi engine --- lib/plugins/engines/gpsshogi.rb | 61 +++++++++++++++++++++++++++++++++++++++++ lib/plugins/engines/loader.rb | 4 +++ 2 files changed, 65 insertions(+) create mode 100644 lib/plugins/engines/gpsshogi.rb diff --git a/lib/plugins/engines/gpsshogi.rb b/lib/plugins/engines/gpsshogi.rb new file mode 100644 index 0000000..d56c9b1 --- /dev/null +++ b/lib/plugins/engines/gpsshogi.rb @@ -0,0 +1,61 @@ +# Copyright (c) 2009 Paolo Capriotti +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +require 'plugins/plugin' +require 'interaction/match' +require_bundle 'engines', 'engine' + +class GPSShogiEngine < Engine + include Plugin + + plugin :name => 'GPSShogi Engine Protocol', + :protocol => 'GPSShogi', + :interface => :engine + + def on_move(data) + text = @serializer.serialize(data[:move], data[:old_state]) + send_command text + end + + def on_engine_start + send_command "new" + if @color == :black + send_command "black" + send_command "go" + else + send_command "white" + end + end + + def extra_command(text) + if text =~ /^[0-9]*\. (\.\.\.) (\S+)/ + move = @serializer.deserialize($2, @match.state) + if move + @match.move(self, move) + end + end + end + + def on_close(data) + send_command "quit" + @engine.kill + end + + 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" + else + send_command "white" + end + manager.undo(self, 2) + end +end diff --git a/lib/plugins/engines/loader.rb b/lib/plugins/engines/loader.rb index 338e558..6bc44ae 100644 --- a/lib/plugins/engines/loader.rb +++ b/lib/plugins/engines/loader.rb @@ -27,6 +27,10 @@ class EngineLoader 'gnushogi' => { :name => 'GNU Shogi', :game => :shogi, :protocol => 'GNUShogi', + :workdir => '/tmp' }, + 'gpsshogi' => { :name => 'GPSShogi', + :game => :shogi, + :protocol => 'GPSShogi', :workdir => '/tmp' } } attr_accessor :name -- 2.11.4.GIT