reuse dice for subsequent legs in randomGame
This commit is contained in:
parent
d9efaf33e7
commit
63df46eee6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*.exe
|
||||
profile_results.txt
|
||||
callgrind.out.*
|
@ -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)))
|
||||
|
@ -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 =
|
||||
|
Loading…
x
Reference in New Issue
Block a user