From 3a1cbfe23a3d06c3c30828c623a089868cff0670 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 2 Oct 2016 15:34:27 +0200 Subject: Add saw-tooth move and multiple moves per level --- src/Update/CloudUpdate.elm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/Update/CloudUpdate.elm') 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 -- cgit v1.2.3