aboutsummaryrefslogtreecommitdiff
path: root/src/Update
diff options
context:
space:
mode:
authorJoris2016-10-03 20:24:59 +0200
committerJoris2016-10-03 20:24:59 +0200
commit2a11b28d2ee636eb730dbb5767104aeac9936afa (patch)
treec7261376073d9334007d24fbe67acda6e11943fa /src/Update
parentc79aae101926d3e5a123b707dd1324dca50994b7 (diff)
parent3a1cbfe23a3d06c3c30828c623a089868cff0670 (diff)
Merge branch 'master' into demo
Diffstat (limited to 'src/Update')
-rw-r--r--src/Update/CloudUpdate.elm11
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