diff options
author | Joris | 2016-10-02 15:34:27 +0200 |
---|---|---|
committer | Joris | 2016-10-02 15:34:27 +0200 |
commit | 3a1cbfe23a3d06c3c30828c623a089868cff0670 (patch) | |
tree | 2c81f1f218f92656fdb2026ffedb423d9d06b76a /src/Update | |
parent | fbab0129f902bf2c3ef07c92deb7674384c18424 (diff) |
Add saw-tooth move and multiple moves per level
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 |