Akadine/new-cg-brutaltester: A local arena for codingame multiplayer

I have recoded the cg-brutal-tester in c++20! Tell me what you think, and please contribute if you can:

1 Like

Just for the record, my own small brutaltester in Ruby :slight_smile:

#! /usr/bin/env ruby

require 'open3'
require 'fileutils'

def round(referee, p1, p2, seed="")
  opt =""
  opt = "-d #{seed}" if seed.size !=0
  cmd = "#{referee} #{opt} -p1 \"#{p1}\" -p2 \"#{p2}\""

  stdout, stderr, = Open3.capture3(cmd)

  s = stdout.chomp.split(/\n/)
  a = s[-3].to_i
  b = s[-2].to_i
  c = s[-1]

  if stderr && !stderr.empty?
    warn stderr.split(/\n/).map { |l| 'e> ' + l } * "\n"
    warn "e> was #{a} #{b}"
  end

  if a > b
    return 1.0, c
  elsif a < b
    return 0.0, c 
  end
  
  return  0.5, c 
 
end

def match(referee, ourself, opponent, threads, parties)
  score = 0

  nb = parties / threads
  reste = parties % threads
  th = []

  score = Array.new(threads, 0.0)
  threads.times do |i|
    my_nb = nb
    my_nb += 1 if i < reste

    th <<  Thread.new do
      s1 = 0.0
      my_nb.times do
        a, s = round(referee, ourself, opponent)
        b,_ = round(referee, opponent, ourself, s)

        s1 = s1 + a + ( 1 - b)
      end
      score[i] += s1
    end
  end

  th.map(&:join) # Wait for all threads to finish
  score.sum
end

# Find the best checkpoints

require 'optparse'

parties = 50
threads = 1

ourself = ''
referee = 'java -jar ./cultists-arena-1.0-SNAPSHOT.jar'
opponent = ''

OptionParser.new do |opts|
  opts.banner = "Usage #{$PROGRAM_NAME} -p1 opponent -p2 player  [-n parties] [-t threads]"

  opts.on('-nNumber', '--games number', Integer, 'Number of Games Pairs') do |n|
    parties = n
  end

  opts.on('-tThreads', '--threads Number', Integer, 'Number of Threads') do |t|
    threads = t
  end

  opts.on('-oOpponent', '--p1 opponent', String, "Lancement de l'adversaire") do |p|
    opponent = p
  end

  opts.on('-qPlayer', '--p2 player', String, 'Lancement du joueur') do |p|
    ourself = p
  end

  opts.on('-rReferee', '--referee referee', String, 'Lancement du referee') do |r|
    referee = r
  end
end.parse!

warn "Compute #{parties} on #{threads} threads (intended!)"

score = match(referee, ourself, opponent, threads, parties)
score = score * 50.0 / parties

puts "Result #{ourself} = #{score}%, #{opponent} = #{100 - score}%"

No compiler, easy to modify, extend. Enjoy (or not!)

1 Like