Skat Engine und AI auf Haskell Basis
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

33 lignes
897B

  1. module Utils where
  2. import System.Random
  3. import Text.Read
  4. shuffle :: StdGen -> [a] -> [a]
  5. shuffle g xs = shuffle' (randoms g) xs
  6. shuffle' :: [Int] -> [a] -> [a]
  7. shuffle' _ [] = []
  8. shuffle' (i:is) xs = let (firsts, rest) = splitAt (1 + i `mod` length xs) xs
  9. in (last firsts) : shuffle' is (init firsts ++ rest)
  10. chunksOf :: Int -> [a] -> [[a]]
  11. chunksOf n [] = []
  12. chunksOf n xs = take n xs : chunksOf n (drop n xs)
  13. query :: Read a => String -> IO a
  14. query s = do
  15. putStrLn s
  16. l <- fmap readMaybe getLine
  17. case l of
  18. Just x -> return x
  19. Nothing -> query s
  20. remove :: (a -> Bool) -> [a] -> (a, [a])
  21. remove pred xs = foldr f (undefined, []) xs
  22. where f c (old, cs) = if pred c then (c, cs) else (old, c : cs)
  23. filterMap :: (a -> Bool) -> (a -> b) -> [a] -> [b]
  24. filterMap pred f as = foldr g [] as
  25. where g a bs = if pred a then f a : bs else bs