clear tiles as well as camels when setting state

This commit is contained in:
Joseph Montanaro 2021-11-02 18:09:18 -07:00
parent 4995a9388b
commit d9efaf33e7
4 changed files with 15 additions and 4 deletions

View File

@ -121,9 +121,11 @@ proc display*(b: Board, start, stop: int) =
proc setState*(b: var Board; state: GameState) =
for color, pos in b.camels:
if pos > 0:
b[pos].camels.clear()
for sq in b.squares.mitems:
if sq.camels.len > 0:
sq.camels.clear()
elif sq.tile.isSome:
sq.tile = none[Tile]()
for (color, dest) in state.camels: # note that `camels` is ordered, as this determines stacking
b[dest].camels.add(color)

View File

@ -1,4 +1,4 @@
import cpuinfo, math, options, random, tables
import cpuinfo, math, options, random, sequtils, tables
import combinators, game, fixedseq
@ -54,6 +54,11 @@ iterator legEndStates(b: Board): Board =
proc getLegScores*(b: Board): ScoreSet =
# special case if all dice have been rolled
if allIt(b.diceRolled, it):
inc result[b.leader]
return result
for prediction in b.legEndStates:
inc result[prediction.leader]

4
test.nims Normal file
View File

@ -0,0 +1,4 @@
--threads: on
--d: danger
--d: lto
--opt: speed