Delete cruft, add Reader monad to some internal ai

This commit is contained in:
jgk
2021-05-16 21:42:11 +02:00
parent 0798cc0b0e
commit d7fcdbf550
69 changed files with 721 additions and 2894 deletions
+4 -4
View File
@@ -12,7 +12,7 @@ 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 (x:y:ys) = state (randomR (x,y)) : f ys
f _ = []
takeOne :: RandomGen g => [a] -> State g a
@@ -20,7 +20,7 @@ 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)))
>>= (\w -> return (xs !! i w ws))
where
i y (z:zs)
| y <= z = 0
@@ -35,11 +35,11 @@ takeOneMore (xs,ys) = do
return (w:xs, zs ++ ws)
takeNMore :: RandomGen g => Int -> ([a],[a]) -> State g ([a],[a])
takeNMore n p = foldr (const ((=<<) takeOneMore)) (return p) [1..n]
takeNMore n p = foldr (const (>>= takeOneMore)) (return p) [1..n]
takeN :: RandomGen g => Int -> [a] -> State g [a]
takeN 0 xs = return []
takeN i xs = fmap fst $ takeNMore i ([],xs)
takeN i xs = fst <$> takeNMore i ([],xs)
-- | Randomly shuffle a list.
shuffle :: RandomGen g => [a] -> State g [a]