import random, times import fixedseq, game, simulation proc randomDice(r: var Rand): seq[tuple[c: Color, p: int]] = for c in Color: let v = r.rand(1..3) result.add((c, v)) result.shuffle proc testGames(n: SomeInteger = 100): auto = var r = initRand(rand(int64)) let dice = randomDice(r) var b: Board b.init b.setState(dice, []) b.display(1, 5) let startTime = cpuTime() let scores = b.randomGames(n) result = cpuTime() - startTime scores.display() proc testLegs(n: Natural = 100): auto = var boards: seq[Board] var r = initRand(rand(int64)) for i in 1 .. n: var b: Board b.init let dice = randomDice(r) b.setState(dice, []) boards.add(b) stdout.write("Constructed: " & $i & "\r") echo "" echo "Running..." let start = cpuTime() for b in boards: discard b.getLegScores result = cpuTime() - start when isMainModule: randomize() # let start_states = 2_000 # let executionTime = testLegs(start_states) # echo "Execution time: ", executionTime # echo "Leg simulations per second: ", float(start_states * 29_160) / executionTime for i in 1 .. 1: let num_games = 100_000_005 let executionTime = testGames(num_games) echo "Execution time: ", executionTime echo "Full-game simulations per second: ", float(num_games) / executionTime echo ""