diff --git a/.gitignore b/.gitignore index 4d8d0fc..1756b4b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.exe -profile_results.txt \ No newline at end of file +profile_results.txt +callgrind.out.* \ No newline at end of file diff --git a/combinators.nim b/combinators.nim index 903d1a7..57d9233 100644 --- a/combinators.nim +++ b/combinators.nim @@ -1,4 +1,4 @@ -import algorithm, random, sugar +import algorithm import fixedseq, game @@ -87,10 +87,3 @@ iterator possibleFutures*(dice: FixedSeq): auto = for i in 0 .. dice.high: f.add((perm[i], digits[i])) yield f - - -proc randomFuture*(dice: FixedSeq, r: var Rand): FixedSeq[5, Die, int8] = - result.initFixedSeq - let order = dice.dup(shuffle(r)) - for i, color in order: - result.add((color, r.rand(1..3))) diff --git a/simulation.nim b/simulation.nim index 38b4da6..425d718 100644 --- a/simulation.nim +++ b/simulation.nim @@ -69,12 +69,18 @@ proc getLegScores*(b: Board): ScoreSet = proc randomGame*(b: Board, r: var Rand): Color = var projection = b + var dice = projection.diceRemaining + while true: - for roll in randomFuture(projection.diceRemaining, r): - projection.advance(roll) + dice.shuffle(r) + for color in dice: + projection.advance((color, r.rand(1..3))) if projection.gameOver: return projection.winner.get - projection.resetDice() + # if we started with <5 dice, we need to reset for the next full leg + if dice.len < 5: + projection.resetDice() + dice = projection.diceRemaining proc randomGamesWorker(b: Board, count: Natural, r: var Rand): ScoreSet =