From d9efaf33e7bc94966086c6aa9334d06db068cbc4 Mon Sep 17 00:00:00 2001 From: Joseph Montanaro Date: Tue, 2 Nov 2021 18:09:18 -0700 Subject: [PATCH] clear tiles as well as camels when setting state --- config.nims => cup.nims | 0 game.nim | 8 +++++--- simulation.nim | 7 ++++++- test.nims | 4 ++++ 4 files changed, 15 insertions(+), 4 deletions(-) rename config.nims => cup.nims (100%) create mode 100644 test.nims diff --git a/config.nims b/cup.nims similarity index 100% rename from config.nims rename to cup.nims diff --git a/game.nim b/game.nim index d9f1f83..f879ce7 100644 --- a/game.nim +++ b/game.nim @@ -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) diff --git a/simulation.nim b/simulation.nim index 6179af1..38b4da6 100644 --- a/simulation.nim +++ b/simulation.nim @@ -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] diff --git a/test.nims b/test.nims new file mode 100644 index 0000000..ada9020 --- /dev/null +++ b/test.nims @@ -0,0 +1,4 @@ +--threads: on +--d: danger +--d: lto +--opt: speed