more variance testing

This commit is contained in:
Joseph Montanaro 2021-07-13 16:16:47 -07:00
parent bcf87a10fd
commit bd413da9a3
2 changed files with 34 additions and 10 deletions

View File

@ -6,8 +6,8 @@ type
ScoreSet* = array[Color, int]
ScoreSpread = object
lo: array[Color, float]
hi: array[Color, float]
lo*: array[Color, float]
hi*: array[Color, float]
LegResults* = tuple[scores: ScoreSet, endStates: CountTable[Board]]
@ -76,7 +76,9 @@ type WorkerArgs = object
board: Board
count: Natural
seed: int64
# have to do these at the module level so they can be shared
# have to do this at the module level so it can be shared
var gamesChannel: Channel[ScoreSet]
gamesChannel.open()

View File

@ -1,4 +1,4 @@
import random, times
import math, random, strformat, times
import fixedseq, game, simulation
@ -42,6 +42,26 @@ proc testLegs(n: Natural = 100): auto =
result = cpuTime() - start
proc testSpread(nTests, nSamples: Natural) =
var b: Board
b.init
var r = initRand(rand(int64))
let dice = randomDice(r)
b.setState(dice, [])
b.display(1, 5)
let spread = randomSpread(b, nTests, nSamples)
stdout.writeLine("Variance:")
for c in Color:
let variance = 100 * (spread.hi[c] - spread.lo[c])
stdout.writeLine(fmt"{c}: {round(variance, 2):.2f}%")
let diff = 100 * (max(spread.hi) - min(spread.lo))
stdout.writeLine(fmt"Win percentage differential: {round(diff, 2):.2f}%")
stdout.flushFile()
when isMainModule:
randomize()
# let start_states = 2_000
@ -49,9 +69,11 @@ when isMainModule:
# 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 ""
# 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 ""
testSpread(100, 1_000_000)