Add procedural room made up of four corners
This commit is contained in:
+11
-6
@@ -1,5 +1,7 @@
|
||||
{-
|
||||
Helpers for random generation.
|
||||
-}
|
||||
module Dodge.RandomHelp where
|
||||
|
||||
import Geometry
|
||||
import Geometry.Data
|
||||
|
||||
@@ -9,8 +11,9 @@ import Data.List
|
||||
|
||||
randomRanges :: (Random a,RandomGen g) => [a] -> State g a
|
||||
randomRanges xs = join $ takeOne $ f xs
|
||||
where f (x:y:ys) = (state (randomR (x,y))) : (f ys)
|
||||
f _ = []
|
||||
where
|
||||
f (x:y:ys) = (state (randomR (x,y))) : (f ys)
|
||||
f _ = []
|
||||
|
||||
takeOne :: RandomGen g => [a] -> State g a
|
||||
takeOne xs = state (randomR (0,length xs - 1)) >>= (\i -> return (xs !! i))
|
||||
@@ -18,9 +21,11 @@ takeOne xs = state (randomR (0,length xs - 1)) >>= (\i -> return (xs !! i))
|
||||
takeOneWeighted :: (RandomGen g, Random b, Ord b, Num b) => [b] -> [a] -> State g a
|
||||
takeOneWeighted ws xs = state (randomR (0, sum ws))
|
||||
>>= (\w -> return (xs !! (i w ws)))
|
||||
where i y (z:zs) | y <= z = 0
|
||||
| otherwise = 1 + i (y-z) zs
|
||||
i y _ = 0
|
||||
where
|
||||
i y (z:zs)
|
||||
| y <= z = 0
|
||||
| otherwise = 1 + i (y-z) zs
|
||||
i y _ = 0
|
||||
|
||||
takeOneMore :: RandomGen g => ([a],[a]) -> State g ([a],[a])
|
||||
takeOneMore (xs,[]) = error "trying to takeOneMore from empty list"
|
||||
|
||||
Reference in New Issue
Block a user