more variance testing
This commit is contained in:
parent
bcf87a10fd
commit
bd413da9a3
@ -6,8 +6,8 @@ type
|
|||||||
ScoreSet* = array[Color, int]
|
ScoreSet* = array[Color, int]
|
||||||
|
|
||||||
ScoreSpread = object
|
ScoreSpread = object
|
||||||
lo: array[Color, float]
|
lo*: array[Color, float]
|
||||||
hi: array[Color, float]
|
hi*: array[Color, float]
|
||||||
|
|
||||||
LegResults* = tuple[scores: ScoreSet, endStates: CountTable[Board]]
|
LegResults* = tuple[scores: ScoreSet, endStates: CountTable[Board]]
|
||||||
|
|
||||||
@ -76,7 +76,9 @@ type WorkerArgs = object
|
|||||||
board: Board
|
board: Board
|
||||||
count: Natural
|
count: Natural
|
||||||
seed: int64
|
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]
|
var gamesChannel: Channel[ScoreSet]
|
||||||
gamesChannel.open()
|
gamesChannel.open()
|
||||||
|
|
||||||
|
36
test.nim
36
test.nim
@ -1,4 +1,4 @@
|
|||||||
import random, times
|
import math, random, strformat, times
|
||||||
import fixedseq, game, simulation
|
import fixedseq, game, simulation
|
||||||
|
|
||||||
|
|
||||||
@ -42,6 +42,26 @@ proc testLegs(n: Natural = 100): auto =
|
|||||||
result = cpuTime() - start
|
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:
|
when isMainModule:
|
||||||
randomize()
|
randomize()
|
||||||
# let start_states = 2_000
|
# let start_states = 2_000
|
||||||
@ -49,9 +69,11 @@ when isMainModule:
|
|||||||
# echo "Execution time: ", executionTime
|
# echo "Execution time: ", executionTime
|
||||||
# echo "Leg simulations per second: ", float(start_states * 29_160) / executionTime
|
# echo "Leg simulations per second: ", float(start_states * 29_160) / executionTime
|
||||||
|
|
||||||
for i in 1 .. 1:
|
# for i in 1 .. 1:
|
||||||
let num_games = 100_000_005
|
# let num_games = 100_000_005
|
||||||
let executionTime = testGames(num_games)
|
# let executionTime = testGames(num_games)
|
||||||
echo "Execution time: ", executionTime
|
# echo "Execution time: ", executionTime
|
||||||
echo "Full-game simulations per second: ", float(num_games) / executionTime
|
# echo "Full-game simulations per second: ", float(num_games) / executionTime
|
||||||
echo ""
|
# echo ""
|
||||||
|
|
||||||
|
testSpread(100, 1_000_000)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user