kayabot 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/kayabot.gemspec +3 -3
  2. data/lib/gg.rb +17 -11
  3. data/lib/kayabot.rb +20 -9
  4. metadata +7 -7
data/kayabot.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "kayabot"
3
- s.version = "0.1.6"
3
+ s.version = "0.1.7"
4
4
  s.summary = "Interface to run Go Bots on Kaya"
5
- s.description = "This is an interface to run GTP compliant Go Bots on Kaya."
5
+ s.description = "This is an interface to run GTP compliant Go Bots on Kaya. "
6
6
  s.authors = ["Gabriel Benmergui"]
7
7
  s.email = ["gabriel.benmergui@kaya.gs"]
8
8
  s.homepage = "http://github.com/conanbatt/OpenKaya"
9
9
 
10
10
  s.executables.push("kayabot")
11
11
 
12
- s.add_dependency("mechanize")
12
+ s.add_dependency("mechanize", '= 1.0.0')
13
13
  s.add_dependency("json")
14
14
 
15
15
  s.files = Dir[
data/lib/gg.rb CHANGED
@@ -1,10 +1,14 @@
1
1
  class GTP
2
2
 
3
3
  def self.run(bot_type, &command)
4
+
4
5
  if bot_type == 'gnugo'
5
6
  new(IO.popen("gnugo --mode gtp", "r+"), &command)
6
7
  elsif bot_type == 'fuego'
7
8
  new(IO.popen("fuego", "r+"), &command)
9
+ else
10
+ ## All falls here to accept commands from the yaml directly
11
+ new(IO.popen(bot_type, "r+"), &command)
8
12
  end
9
13
  end
10
14
 
@@ -37,6 +41,10 @@ class GTP
37
41
  send_command(:loadsgf, path)
38
42
  end
39
43
 
44
+ def score(path)
45
+ send_command(:score, "aftermath", path)
46
+ end
47
+
40
48
  def list_stones(color)
41
49
  @io.puts [:list_stones, color].join(" ")
42
50
  return self.clean_gtp_response
@@ -70,7 +78,7 @@ class GTP
70
78
  end
71
79
  end
72
80
 
73
- SGF_FILE_PATH = "gnugo_games/"
81
+ SGF_FILE_PATH = "bot_games/"
74
82
 
75
83
  def score_game(game_id, game_sgf)
76
84
  re = nil
@@ -81,14 +89,12 @@ def score_game(game_id, game_sgf)
81
89
  File.open(filepath, "w") do |f|
82
90
  f.write game_sgf
83
91
  end
84
-
85
- IO.popen("gnugo --score aftermath #{filepath}") do |f|
86
- re = f.read
87
- end
92
+
88
93
  dead_stones = ""
89
- GTP.run("gnugo") do |gtp|
94
+ GTP.run(@bot) do |gtp|
90
95
  gtp.loadsgf filepath
91
96
  dead_stones = gtp.list_dead_stones
97
+ re = gtp.final_score
92
98
  end
93
99
 
94
100
  p dead_stones
@@ -110,13 +116,12 @@ def ai_move(game_id, game_sgf, color)
110
116
  end
111
117
 
112
118
  size = 19
113
- GTP.run(@bot || "gnugo") do |gtp|
119
+ GTP.run(@bot) do |gtp|
114
120
  gtp.loadsgf filepath
115
121
  size = @master_node.match(/SZ\[(\d+)\]/)[1]
116
122
  re = gtp.genmove color
117
123
  end
118
- p re
119
- p size
124
+ p "Bot generated #{re}"
120
125
  move = convert_move(re,size)
121
126
 
122
127
  File.delete(filepath)
@@ -125,12 +130,13 @@ end
125
130
 
126
131
  #switches GTP move into sgf-like coordinate
127
132
  def convert_move(move, size=19)
128
- if move == "PASS"
133
+ if move.downcase == "pass"
129
134
  return 'pass'
130
- elsif move == "resign"
135
+ elsif move.downcase == "resign"
131
136
  return 'resign'
132
137
  else
133
138
 
139
+
134
140
  alphabet = "ABCDEFGHIJKLMNOPQRS"[0..size.to_i - 1]
135
141
 
136
142
  sgf_alphabet = "ABCDEFGHJKLMNOPQRST"[0..size.to_i - 1]
data/lib/kayabot.rb CHANGED
@@ -13,6 +13,8 @@ class KayaBot
13
13
  SCORE_URL = "/bot/score"
14
14
  VERSION = Gem::Specification.find_by_name("kayabot").version.to_s
15
15
 
16
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
17
+
16
18
  attr_accessor :challenger, :status, :move
17
19
 
18
20
  def initialize(config)
@@ -24,7 +26,7 @@ class KayaBot
24
26
  @title = config["title"]
25
27
  @bot = config["bot"]
26
28
  @agent = Mechanize.new
27
- @status
29
+ @error_limit = 3
28
30
  @sgf
29
31
  end
30
32
 
@@ -40,13 +42,23 @@ class KayaBot
40
42
  TIME_LAPSE = 4
41
43
 
42
44
  def listener_loop
43
- while (true) do
44
- connect
45
- fetch_and_parse_data
46
- open_game if @status=="connected" || @status=="finished"
47
- post_score if @status=="scoring"
48
- post_move if @bots_turn && @status=="playing"
49
- sleep TIME_LAPSE #lets not explode in requests
45
+ begin
46
+ while (true) do
47
+ connect
48
+ fetch_and_parse_data
49
+ open_game if @status=="connected" || @status=="finished"
50
+ post_score if @status=="scoring"
51
+ post_move if @bots_turn && @status=="playing"
52
+ sleep TIME_LAPSE #lets not explode in requests
53
+ end
54
+ rescue SystemExit, Interrupt
55
+ raise
56
+ rescue Exception => e
57
+ p "There was an error. Will try to run again. If problems persist, contact Kaya at info@kaya.gs"
58
+ p e
59
+ p e.backtrace[0]
60
+ sleep 5
61
+ listener_loop
50
62
  end
51
63
  end
52
64
 
@@ -75,7 +87,6 @@ class KayaBot
75
87
  bot_move = ";#{color_short}[#{bot_move}]#{color_short}L[#{(25*60) - (@move ? @move.count(";") : 1)}]"
76
88
  @agent.post(@server_url+ PLAY_URL,
77
89
  :move => bot_move)
78
- #@sgf.add_move(bot_move)
79
90
  @move = nil
80
91
  end
81
92
  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.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-31 00:00:00.000000000 Z
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 1.0.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: json
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: This is an interface to run GTP compliant Go Bots on Kaya.
46
+ description: ! 'This is an interface to run GTP compliant Go Bots on Kaya. '
47
47
  email:
48
48
  - gabriel.benmergui@kaya.gs
49
49
  executables: