diff options
author | Joris | 2016-10-03 20:24:59 +0200 |
---|---|---|
committer | Joris | 2016-10-03 20:24:59 +0200 |
commit | 2a11b28d2ee636eb730dbb5767104aeac9936afa (patch) | |
tree | c7261376073d9334007d24fbe67acda6e11943fa /src/Update/CloudUpdate.elm | |
parent | c79aae101926d3e5a123b707dd1324dca50994b7 (diff) | |
parent | 3a1cbfe23a3d06c3c30828c623a089868cff0670 (diff) |
Merge branch 'master' into demo
Diffstat (limited to 'src/Update/CloudUpdate.elm')
-rw-r--r-- | src/Update/CloudUpdate.elm | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Update/CloudUpdate.elm b/src/Update/CloudUpdate.elm index 559acc9..d8ccf36 100644 --- a/src/Update/CloudUpdate.elm +++ b/src/Update/CloudUpdate.elm @@ -3,6 +3,7 @@ module Update.CloudUpdate exposing ) import List +import List.Nonempty as NE exposing (Nonempty(..), (:::)) import Random.Pcg as Random exposing (Seed, Generator) import Model.Vec2 exposing (..) @@ -58,17 +59,23 @@ getNewPoint : Float -> Vec2 -> Seed -> Int -> (Point, Seed) getNewPoint elapsedTime boardSize seed currentScore = let (initPos, seed') = pointInitPos boardSize seed (initDest, seed'') = pointDestination boardSize seed' + (randomMove, seed''') = Random.step (nonemptySample << .moves <| currentLevel currentScore) seed'' in ( { initTime = elapsedTime , initPos = initPos , initDest = initDest , move = \initTime initPos initDest elapsedTime -> let delta = elapsedTime - initTime - move = (currentLevel currentScore).move initPos initDest delta + move = randomMove initPos initDest delta in initPos `add` move } - , seed'' + , seed''' ) +nonemptySample : Nonempty a -> Random.Generator a +nonemptySample nonempty = + Random.int 0 (NE.length nonempty - 1) + |> Random.map (\i -> NE.get i nonempty) + pointInitPos : Vec2 -> Seed -> (Vec2, Seed) pointInitPos boardSize seed = let (rand, seed') = Random.step (Random.float 0 1) seed |