Skat Engine und AI auf Haskell Basis
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

38 rindas
1.0KB

  1. module Skat.AI.Human where
  2. import Control.Monad.Trans (liftIO)
  3. import Skat.Player
  4. import Skat.Pile
  5. import Skat.Card
  6. import Skat.Utils
  7. import Skat.Render
  8. data Human = Human { getTeam :: Team
  9. , getHand :: Hand }
  10. deriving Show
  11. instance Player Human where
  12. team = getTeam
  13. hand = getHand
  14. chooseCard p table _ hand = do
  15. trumpCol <- trump
  16. turnCol <- turnColour
  17. let possible = filter (isAllowed trumpCol turnCol hand) hand
  18. c <- liftIO $ askIO (map getCard table) (map toCard possible) (map toCard hand)
  19. return $ (c, p)
  20. askIO :: [Card] -> [Card] -> [Card] -> IO Card
  21. askIO table possible hand = do
  22. putStrLn "Your hand"
  23. render hand
  24. putStrLn "These options are possible"
  25. render possible
  26. putStrLn "These cards are on the table"
  27. render table
  28. idx <- query
  29. "Which card do you want to play? Give the index of the card"
  30. if idx >= 0 && idx < length possible
  31. then return $ possible !! idx
  32. else askIO table possible hand