I think I'm seeing some unusual behavior while generating a random value.
I'm trying to sample multiple (x,y) pairs from a set of available (x,y),
and then sample again from the remaining pairs. The final set (which
shouldn't contain any items from the first set), seemed to contain items
from the first set. So, I added some Debug.log calls in hope of getting a
peek into the random values as they are being generated, and I noticed that
one of the log calls was occurring twice. I've included the log calls and
the console output below.
randomGame : Int -> Random.Generator Model
randomGame level =
let numTargets = 5 + level
numMines = (25 - numTargets) // 2
rMines =
allPoss
|> randomPoss numMines
|> Random.map (log "mines")
rTargetPoss =
rMines
|> Random.map (Set.diff allPoss)
|> Random.map (log "possible target positions")
rTargets =
rTargetPoss
`Random.andThen` (randomTargets numTargets)
|> Random.map (log "targets")
in
Random.map2 (\ms ts -> {mines=ms, targets=ts, exposed=Set.empty})
rMines rTargets
|> Random.map (log "model")
<https://lh3.googleusercontent.com/-MTa2mUiWS4c/V8JWkl481MI/AAAAAAAACGk/Zw96lxg4cDU32R3TR_3WQaGpBWTDlUgegCLcB/s1600/Screenshot%2Bfrom%2B2016-08-27%2B22-12-01.png>
It logs "mines" twice. The first time seems to be the value that is kept
for the model, but the second "mines" is used to generate the possible
target positions.
The full source code (< 350 lines) is at
https://github.com/natec425/Voltorb-Flip/blob/master/game.elm. Any help
would be greatly appreciated.
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.