kayabot 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/kayabot.gemspec +1 -1
- data/lib/kayabot.rb +33 -10
- metadata +2 -2
data/kayabot.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "kayabot"
|
3
|
-
s.version = "0.1.
|
3
|
+
s.version = "0.1.9"
|
4
4
|
s.summary = "Interface to run Go Bots on Kaya"
|
5
5
|
s.description = "This is an interface to run GTP compliant Go Bots on Kaya. Modified version for Zen."
|
6
6
|
s.authors = ["Gabriel Benmergui"]
|
data/lib/kayabot.rb
CHANGED
@@ -12,6 +12,7 @@ class KayaBot
|
|
12
12
|
RESIGN_URL = "/bot/resign"
|
13
13
|
SCORE_URL = "/bot/score"
|
14
14
|
CLOSE_GAME_URL = "/bot/close_game"
|
15
|
+
ERROR_REPORT_URL = "/bot/error"
|
15
16
|
VERSION = Gem::Specification.find_by_name("kayabot").version.to_s
|
16
17
|
|
17
18
|
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
@@ -27,8 +28,9 @@ class KayaBot
|
|
27
28
|
@title = config["title"]
|
28
29
|
@bot = config["bot"]
|
29
30
|
@agent = Mechanize.new
|
31
|
+
@agent.max_history = 2
|
30
32
|
@error_limit = 3
|
31
|
-
@
|
33
|
+
@loop_reading = 50
|
32
34
|
end
|
33
35
|
|
34
36
|
def game_configuration
|
@@ -36,15 +38,17 @@ class KayaBot
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def connect
|
39
|
-
return if @agent.cookies.last && @agent.cookies.last.name == "
|
41
|
+
return if @agent.cookies.last && @agent.cookies.last.name == "rack.session"
|
40
42
|
page = @agent.post(@server_url+ "/session/create", {:id => @user, :password => @pass})
|
43
|
+
page.body
|
41
44
|
end
|
42
45
|
|
43
46
|
TIME_LAPSE = 4
|
44
47
|
|
45
48
|
def listener_loop
|
46
|
-
begin
|
49
|
+
begin
|
47
50
|
while (true) do
|
51
|
+
$stdout.puts GC::Profiler.report
|
48
52
|
connect
|
49
53
|
fetch_and_parse_data
|
50
54
|
open_game if @status=="connected" || @status=="finished"
|
@@ -59,6 +63,9 @@ class KayaBot
|
|
59
63
|
$stderr.puts "There was an error. Will try to run again. If problems persist, contact Kaya at info@kaya.gs"
|
60
64
|
$stderr.puts e
|
61
65
|
$stderr.puts e.backtrace[0]
|
66
|
+
btrace = ""
|
67
|
+
e.backtrace.each {|line| btrace < "\n#{line}"}
|
68
|
+
post_error(e.to_s,btrace)
|
62
69
|
sleep 5
|
63
70
|
listener_loop
|
64
71
|
end
|
@@ -73,10 +80,12 @@ class KayaBot
|
|
73
80
|
@bots_turn = json["bot_play?"]
|
74
81
|
@color = json["next"]
|
75
82
|
@master_node = json["sgf_master_node"]
|
83
|
+
page.body
|
76
84
|
end
|
77
85
|
|
78
86
|
def open_game
|
79
|
-
@agent.post(@server_url+ OPEN_GAME_URL, game_configuration)
|
87
|
+
res = @agent.post(@server_url+ OPEN_GAME_URL, game_configuration)
|
88
|
+
p res.body
|
80
89
|
end
|
81
90
|
def post_move
|
82
91
|
#TODO should insert master node . Need handi/komi
|
@@ -93,17 +102,31 @@ class KayaBot
|
|
93
102
|
end
|
94
103
|
end
|
95
104
|
def resign
|
96
|
-
@agent.post(@server_url+ RESIGN_URL, {:result => "resign"})
|
105
|
+
$stdout.puts (@agent.post(@server_url+ RESIGN_URL, {:result => "resign"}).body)
|
97
106
|
end
|
98
107
|
def close_game
|
99
|
-
@agent.post(@server_url + CLOSE_GAME_URL)
|
108
|
+
res = @agent.post(@server_url + CLOSE_GAME_URL)
|
109
|
+
$stdout.puts res.body
|
100
110
|
end
|
101
111
|
|
102
112
|
def post_score
|
103
113
|
result = score_game("temp", sgf_content)
|
104
114
|
$stdout.puts result
|
105
|
-
@agent.post(@server_url+ SCORE_URL, {:score => parse_result_from_bot(result[:score]), :dead_stones => result[:dead_stones]})
|
115
|
+
res = @agent.post(@server_url+ SCORE_URL, {:score => parse_result_from_bot(result[:score]), :dead_stones => result[:dead_stones]})
|
116
|
+
res.body
|
106
117
|
end
|
118
|
+
|
119
|
+
def post_error(title,exception_message="Unavailable")
|
120
|
+
if @error_limit > 0
|
121
|
+
exception_message = "Unavailable" if exception_message.empty?
|
122
|
+
res = @agent.post(@server_url + ERROR_REPORT_URL, {:title=> title, :content => exception_message})
|
123
|
+
$stdout.puts res.body
|
124
|
+
@error_limit -= 1
|
125
|
+
else
|
126
|
+
$stdout.puts "Error report limit passed."
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
107
130
|
#Black wins by 61.5 points
|
108
131
|
def parse_result_from_bot(result)
|
109
132
|
color = result[0].chr
|
@@ -112,9 +135,9 @@ class KayaBot
|
|
112
135
|
end
|
113
136
|
|
114
137
|
def sgf_content
|
115
|
-
|
116
|
-
|
117
|
-
return "(#{@master_node}#{
|
138
|
+
sgf = SGF.new
|
139
|
+
sgf.add_move(@move) if @move
|
140
|
+
return "(#{@master_node}#{sgf.move_list})"
|
118
141
|
end
|
119
142
|
|
120
143
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kayabot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mechanize
|