reuse dice for subsequent legs in randomGame
This commit is contained in:
parent
d9efaf33e7
commit
63df46eee6
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*.exe
|
*.exe
|
||||||
profile_results.txt
|
profile_results.txt
|
||||||
|
callgrind.out.*
|
@ -1,4 +1,4 @@
|
|||||||
import algorithm, random, sugar
|
import algorithm
|
||||||
import fixedseq, game
|
import fixedseq, game
|
||||||
|
|
||||||
|
|
||||||
@ -87,10 +87,3 @@ iterator possibleFutures*(dice: FixedSeq): auto =
|
|||||||
for i in 0 .. dice.high:
|
for i in 0 .. dice.high:
|
||||||
f.add((perm[i], digits[i]))
|
f.add((perm[i], digits[i]))
|
||||||
yield f
|
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 =
|
proc randomGame*(b: Board, r: var Rand): Color =
|
||||||
var projection = b
|
var projection = b
|
||||||
|
var dice = projection.diceRemaining
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
for roll in randomFuture(projection.diceRemaining, r):
|
dice.shuffle(r)
|
||||||
projection.advance(roll)
|
for color in dice:
|
||||||
|
projection.advance((color, r.rand(1..3)))
|
||||||
if projection.gameOver:
|
if projection.gameOver:
|
||||||
return projection.winner.get
|
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 =
|
proc randomGamesWorker(b: Board, count: Natural, r: var Rand): ScoreSet =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user