Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'pp'
- require 'terminal-table/import'
- require 'progressbar'
- EXAMPLE_BOTS = {
- :BullyBot => "java -jar example_bots/BullyBot.jar",
- :DualBot => "java -jar example_bots/DualBot.jar",
- :RageBot => "java -jar example_bots/RageBot.jar",
- :RandomBot => "java -jar example_bots/RandomBot.jar"
- }
- PLAYERS = {
- :Rezunov => "bots/Rezunov/Rezunov.exe",
- :Svinarenko => "bots/Svinarenko/Svinarenko.exe",
- :Lisenko => "bots/Lisenko/Lisenko.exe"
- }
- class Battle
- @@game_engine = "java -jar tools/PlayGame2.jar"
- @@map_format = "maps/map%d.txt"
- @@game_file = "last_game.txt"
- attr_accessor :first_player, :secont_player, :maps, :results
- def initialize
- @maps = []
- end
- def start(&block)
- @results = {:first => 0, :second => 0}
- @maps.each { |map| play map, &block }
- end
- def play(map_number, &block)
- system "#{@@game_engine} #{@@map_format % map_number} 1000 1000 log.txt \"#{@first_player}\" \"#{@secont_player}\" > null 2> #{@@game_file}"
- File.open(@@game_file).each_line do |line|
- @results[:first] += 1 if line[/Player 1 Wins!/]
- @results[:second] += 1 if line[/Player 2 Wins!/]
- if line[/WARNING/] or line[/ERROR/] then
- puts " " * 80
- puts "#{line} -- 1: #{first_player}, 2: #{secont_player}, map: #{map_number}"
- end
- end
- yield
- end
- end
- battle = Battle.new
- battle.maps = (1..25).map { |e| e * 4 }
- progress = ProgressBar.new("Fighting", battle.maps.count * PLAYERS.count * (PLAYERS.count + EXAMPLE_BOTS.count - 1))
- results = {}
- PLAYERS.each do |player_name, player_command|
- battle.first_player = player_command
- oponents = {}
- oponents.merge! EXAMPLE_BOTS
- oponents.merge! PLAYERS
- oponents.delete player_name
- oponents.each do |bot_name, bot_command|
- battle.secont_player = bot_command
- battle.start {progress.inc }
- results[player_name] ||= {}
- results[player_name][bot_name] = battle.results[:first]
- end
- end
- results_table = table do |t|
- heads = PLAYERS.keys + EXAMPLE_BOTS.keys
- t.headings = ["(Player)"] + heads + ["(Score)"]
- results.each do |player, scores|
- row = []
- total_score = 0
- heads.each do |oponent|
- if scores.has_key? oponent then
- row << scores[oponent]
- total_score += scores[oponent]
- else
- row << "-"
- end
- end
- t.add_row [player] + row + [total_score]
- end
- end
- puts results_table
- File.open("battle_results.txt", "w") do |f|
- f.write results_table
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement