Created
May 18, 2020 13:20
-
-
Save jakecoffman/4e460dbba9d50aefb3b2c093b12f3431 to your computer and use it in GitHub Desktop.
codingame.com Spring Challenge 2020 stress tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.codingame.gameengine.runner.MultiplayerGameRunner | |
import com.codingame.gameengine.runner.dto.GameResult | |
import groovy.time.TimeCategory | |
import groovyx.gpars.GParsPool | |
class Simulator { | |
static final champion = "config/champion.exe" | |
static final challenger = "config/challenger.exe" | |
static void main(String[] args) { | |
final pool = 6 | |
def numGames = (1..100).toArray() | |
println "Running ${numGames.size()} games with pool size ${pool}" | |
def start = new Date() | |
// set to 3 because of a warning about sending too much data to the viewer | |
List<GameResult> results = GParsPool.withPool(pool) { | |
numGames.collectParallel { | |
MultiplayerGameRunner gameRunner = new MultiplayerGameRunner() | |
gameRunner.setSeed(Math.random()*10000 as Long) | |
// gameRunner.setSeed(5108528766889254900) | |
gameRunner.addAgent(champion, "champion", "https://static.codingame.com/servlet/fileservlet?id=43829808065962") | |
gameRunner.addAgent(challenger, "challenger", "https://static.codingame.com/servlet/fileservlet?id=43829821541064") | |
Properties params = new Properties() | |
gameRunner.setGameParameters(params) | |
gameRunner.setLeagueLevel(3) | |
return gameRunner.simulate() | |
} | |
} as List<GameResult> | |
// timings with Python | |
// pool 1: 50s, pool 2: 25s, pool 3: 20s, 4: 18s, 5: 15s, 8: 13s no timeouts | |
def diff = TimeCategory.minus(new Date(), start) | |
println "Done ${diff}" | |
List<GameResult> champion = [] | |
List<GameResult> challenger = [] | |
List<GameResult> championTimeouts = [] | |
List<GameResult> challengerTimeouts = [] | |
List<GameResult> exceptions = [] | |
results.each { | |
if (it.scores[0] > it.scores[1]) { | |
champion.add it | |
} | |
if (it.scores[0] < it.scores[1]) { | |
challenger.add it | |
} | |
if (it.exception != null) { | |
exceptions.add it | |
} | |
if (it.failCause != null) { | |
println "${it.failCause}" | |
} | |
// errors is standard error | |
// def champErr = it.errors["0"].findAll { it != null } | |
// if (champErr.size() > 0) { | |
// println "Champion Err ${champErr.join("--")}" | |
// } | |
// def chalErr = it.errors["1"].findAll { it != null } | |
// if (chalErr.size() > 0) { | |
// println "Challenger error ${chalErr.join("--")}" | |
// } | |
def summary = it.summaries.join("\n") | |
if (summary.contains("0 has not")) { | |
championTimeouts.add it | |
} | |
if (summary.contains("1 has not")) { | |
challengerTimeouts.add it | |
} | |
} | |
println "champion: ${champion.size()} wins, ${championTimeouts.size()} timeouts" | |
println "challenger: ${challenger.size()} wins, ${challengerTimeouts.size()} timeouts" | |
println "Exceptions: ${exceptions.size()}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment