Skat Engine und AI auf Haskell Basis
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

40 строки
1.4KB

  1. import Card
  2. import Pile
  3. import Utils
  4. import qualified Data.Map.Strict as M
  5. import Data.Monoid ((<>))
  6. type Guess = M.Map Card [Hand]
  7. type Distribution = ([Card], [Card], [Card])
  8. distributions :: Guess -> [Distribution]
  9. distributions guess = --filter equilibrated
  10. (helper (M.toList guess) (0, 0, 0))
  11. where helper [] _ = []
  12. helper ((c, hs):[]) ns = map fst (distr c hs ns)
  13. helper ((c, hs):gs) ns =
  14. let dsWithNs = distr c hs ns
  15. go (d, ns') = map (d <>) (helper gs ns')
  16. in concatMap go dsWithNs
  17. distr card hands (n1, n2, n3) =
  18. let f card Hand1 = (([card], [], []), (n1+1, n2, n3))
  19. f card Hand2 = (([], [card], []), (n1, n2+1, n3))
  20. f card Hand3 = (([], [], [card]), (n1, n2, n3+1))
  21. isOk Hand1 = n1 < cardsPerHand
  22. isOk Hand2 = n2 < cardsPerHand
  23. isOk Hand3 = n3 < cardsPerHand
  24. in filterMap isOk (f card) hands
  25. equilibrated (cs1, cs2, cs3) =
  26. let ls = [length cs1, length cs2, length cs3]
  27. in (maximum ls - minimum ls) <= 1
  28. cardsPerHand = (length guess `div` 3)
  29. testguess :: Guess
  30. testguess = foldr (Hand3 `has`) m (take 10 allCards)
  31. where l = map (\c -> (c, [Hand1, Hand2, Hand3])) (take 30 allCards)
  32. m = M.fromList l
  33. main :: IO ()
  34. main = print $ length $ distributions testguess