Class: GoshrineBot::GtpStdioClient
- Inherits:
-
Object
- Object
- GoshrineBot::GtpStdioClient
show all
- Defined in:
- lib/goshrine_bot/gtp_stdio_client.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(command_line, logfile = "gtp.log") ⇒ GtpStdioClient
Returns a new instance of GtpStdioClient.
69
70
71
72
73
74
75
76
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 69
def initialize(command_line, logfile="gtp.log")
@command_line = command_line
puts "Opening #{command_line.inspect} (logging to file '#{logfile}')"
@gtp = EM.popen(@command_line, GtpProcess, "args!")
@gtp.logfile = logfile
@logfile = logfile
log "Starting #{command_line.inspect}"
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodname, *args) ⇒ Object
111
112
113
114
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 111
def method_missing(methodname, *args)
args = args.map {|a| a.to_s}.join(" ")
send("#{methodname.to_s} #{args}")
end
|
Instance Attribute Details
#boardsize(size) ⇒ Object
Returns the value of attribute boardsize.
66
67
68
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 66
def boardsize
@boardsize
end
|
#command_id ⇒ Object
Returns the value of attribute command_id.
65
66
67
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 65
def command_id
@command_id
end
|
#command_line ⇒ Object
Returns the value of attribute command_line.
67
68
69
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 67
def command_line
@command_line
end
|
Instance Method Details
#close ⇒ Object
84
85
86
87
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 84
def close
log "Closing #{command_line.inspect}"
@gtp.close_connection
end
|
#final_status_list(t) ⇒ Object
104
105
106
107
108
109
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 104
def final_status_list(t)
Timeout::timeout(10) do
res = send("final_status_list #{t}")
res.split.map {|c| Position.create(@boardsize, c)}
end
end
|
#kill ⇒ Object
89
90
91
92
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 89
def kill
log "Kill #{command_line.inspect}"
Process.kill 'TERM', @gtp.get_pid
end
|
#log(str) ⇒ Object
78
79
80
81
82
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 78
def log(str)
File.open(@logfile, "a") do |f|
f.write "#{Time.now} - #{str}\n"
end
end
|
#play(color, move) ⇒ Object
99
100
101
102
|
# File 'lib/goshrine_bot/gtp_stdio_client.rb', line 99
def play(color, move)
send("play #{color} #{move}")
end
|