Skip to content

Commit df654c3

Browse files
committed
Wins against external bots count more
1 parent c007187 commit df654c3

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

ruby/run_generation.rb

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def play_round
105105
data['games'].each do |game|
106106
game_data = prepare_game(game)
107107
if game_data['winner']
108-
update_data(game, game_data['winner'])
108+
update_data(game, game_data)
109109
refresh_progress
110110
else
111111
pipe << game_data
@@ -117,16 +117,18 @@ def play_round
117117

118118
_r, completed_game = Ractor.select(*ractors)
119119
result = score_game(completed_game)
120-
update_data(completed_game, result['winner'])
120+
update_data(completed_game, result)
121121
refresh_progress
122122
end
123123
end
124124

125-
def update_data(game, winner)
125+
def update_data(game, result)
126+
winner = result['winner']
127+
points = result['points'] || 1
126128
# Update score
127129
new_ranking = data['ranking'].map do |s|
128130
if s['name'] == winner
129-
s.merge('score' => s['score'] + 1)
131+
s.merge('score' => s['score'] + points)
130132
else
131133
s
132134
end
@@ -156,7 +158,7 @@ def refresh_progress
156158

157159
def prepare_game(game)
158160
# Odd number of players. Received a bye
159-
return { 'winner' => game['black'] } unless game['white']
161+
return { 'winner' => game['black'], 'points' => 1 } unless game['white']
160162

161163
black = data['players'][game['black']]['command']
162164
white = data['players'][game['white']]['command']
@@ -175,8 +177,9 @@ def score_game(game)
175177

176178
prefix = prefix_from(game)
177179
result = File.readlines("#{prefix}.dat").last.split
178-
winner = result[3].start_with?('B') ? game['black'] : game['white']
179-
{ 'winner' => winner }
180+
winner, loser = result[3].start_with?('B') ? [game['black'], game['white']] : [game['white'], game['black']]
181+
points = data['players'][loser]['points']
182+
{ 'winner' => winner, 'points' => points }
180183
end
181184

182185
def prefix_from(game)
@@ -232,23 +235,23 @@ def evolve_from_previous_population
232235

233236
def clean_up_generation(g)
234237
Dir.chdir("../#{g}") do
235-
stdout, stderr, status = Open3.capture3('find . -name "*.ann" -print | tar cvfj anns.tar.bz2 -T -')
236-
if status.success?
237-
FileUtils.rm(Dir['*.ann'])
238-
else
239-
puts 'Failed to tar *.ann files'
240-
puts stdout
241-
puts stderr
242-
exit(1)
243-
end
238+
# stdout, stderr, status = Open3.capture3('find . -name "*.ann" -print | tar cvfj anns.tar.bz2 -T -')
239+
# if status.success?
240+
FileUtils.rm(Dir['*.ann'])
241+
# else
242+
# puts 'Failed to tar *.ann files'
243+
# puts stdout
244+
# puts stderr
245+
# exit(1)
246+
# end
244247
FileUtils.rm(Dir['*.sgf'])
245248
end
246249
end
247250

248-
AMIGO = { 'name' => 'AmiGo', 'command' => 'amigogtp' }
249-
BROWN = { 'name' => 'Brown', 'command' => 'brown' }
250-
GNUGO0 = { 'name' => 'GnuGoLevel0', 'command' => 'gnugo --level 0 --mode gtp' }
251-
GNUGO10 = { 'name' => 'GnuGoLevel10', 'command' => 'gnugo --level 10 --mode gtp' }
251+
AMIGO = { 'name' => 'AmiGo', 'command' => 'amigogtp', 'points' => 4 }
252+
BROWN = { 'name' => 'Brown', 'command' => 'brown', 'points' => 2 }
253+
GNUGO0 = { 'name' => 'GnuGoLevel0', 'command' => 'gnugo --level 0 --mode gtp', 'points' => 10 }
254+
GNUGO10 = { 'name' => 'GnuGoLevel10', 'command' => 'gnugo --level 10 --mode gtp', 'points' => 20 }
252255
EXTERNAL_PLAYERS = [
253256
*(1..5).map { |i| BROWN.merge('name' => BROWN['name'] + i.to_s) },
254257
*(1..10).map { |i| AMIGO.merge('name' => AMIGO['name'] + i.to_s) },
@@ -282,10 +285,10 @@ def games_from_ranking(ranking)
282285

283286
def setup_players
284287
players = EXTERNAL_PLAYERS.each_with_object({}) do |player, hash|
285-
hash[player['name']] = { 'command' => player['command'], 'external' => true }
288+
hash[player['name']] = { 'command' => player['command'], 'points' => player['points'], 'external' => true }
286289
end
287290
players.merge!(Dir['*.ann'].each_with_object({}) do |player, hash|
288-
hash[player] = { 'command' => "../evo #{player}" }
291+
hash[player] = { 'command' => "../evo #{player}", 'points' => 1 }
289292
end)
290293
players
291294
end

0 commit comments

Comments
 (0)