-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlg-castro.rb
87 lines (79 loc) · 1.93 KB
/
lg-castro.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/ruby -W0
require 'lg-interface'
class GTPClient
def initialize(cmdline)
@io=IO.popen(cmdline,'w+')
end
def cmd(c)
@io.puts c.strip
return @io.gets("\n\n")
end
def close
@io.close
end
end
class Castro < LittleGolemInterface
include HavannahCoords
LOGIN='Castro_bot'
PSW='ryraxeku'
BOSS_ID='Fobax'
def initialize
@supported_gametypes = /Hav/
super(LOGIN,PSW,BOSS_ID)
end
def call_castro(size, moves)
gtp = GTPClient.new("./castro")
gtp.cmd("hguicoords")
gtp.cmd("swap 0")
gtp.cmd("boardsize #{size}")
case size
when 4 then gtp.cmd('player_params -g 1')
when 6 then gtp.cmd('player_params -R 50')
when 7 then gtp.cmd('player_params -R 60 -p 1')
when 8 then gtp.cmd('player_params -R 70 -p 1')
when 9 then gtp.cmd('player_params -R 100 -p 1')
when 10 then gtp.cmd('player_params -R 130 -p 1')
end
gtp.cmd("time -r 0 -g 0 -m #{size*60} -f 0")
gtp.cmd("playgame " + moves.select{|m| m != 'swap'}.join(' '))
response = gtp.cmd('genmove')
gtp.cmd('quit')
sleep 1
gtp.close
return response[2..-3] #trim off the = and newlines
end
def parse_make_moves(gameids)
gameids.each do |g|
if (game = get_game(g))
size = game.scan(/SZ\[(.+?)\]/).flatten[0].to_i
moves = game.scan(/;[B|W]\[(.+?)\]/).flatten.map{|m| coord_HGF2GA(m, size) }.compact
self.log("Game #{g}, size #{size}: #{moves.join(' ')}")
newmove = self.call_castro(size, moves)
self.log("Game #{g}, size #{size}: response #{newmove}")
self.post_move(g, coord_GA2LG(newmove, size))
else
self.log('error getting game')
sleep(600)
end
end
end
end
#enable to cause the http library to show warnings/errors
#$VERBOSE = 1
w=Castro.new
w.test_coords
loop {
begin
while w.parse
end
sleep(30)
rescue Timeout::Error => e
p 'timeout error (rbuff_fill exception), try again in 30 seconds'
sleep(30)
rescue => e
p e.message
p e.backtrace
p 'An error... wait 5 minutes'
sleep(300)
end
}