-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmminput.rb
executable file
·55 lines (42 loc) · 880 Bytes
/
mminput.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
#!/usr/bin/ruby
class GTPClient
def initialize(cmdline, newline = "\n")
@io=IO.popen(cmdline,'w+')
@sep = newline + newline
end
def cmd(c)
return [true, ""] if c.strip == ""
@io.puts c.strip
res = @io.gets(@sep).strip.split(' ', 2)
# puts "> #{c} ==> #{res.join ' '}"
res[0] = (res[0] == '=')
return res
end
def close
@io.close
end
end
size = (ARGV[0] || 5).to_i
gtp = GTPClient.new("./castro")
puts "! 4096"
puts "1"
puts "4096 6-pattern"
puts "!"
linenum = 0;
prefix = $0;
$stdin.each_line {|line|
$0 = "#{prefix} - #{linenum}"
linenum += 1;
moves = line.strip.split
gtp.cmd("boardsize #{size}")
moves.each{|move|
patterns = gtp.cmd("patterns")[1]
patterns = Hash[patterns.strip.split("\n").map{|l| l.strip.split }]
puts "#"
puts patterns[move]
puts patterns.values
gtp.cmd("playgame #{move}")
}
}
gtp.cmd("quit")
gtp.close