diff options
Diffstat (limited to 'src/Update')
-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 |