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
996B

  1. module AI.Human where
  2. import Control.Monad.Trans (liftIO)
  3. import Player
  4. import Pile
  5. import Card
  6. import Utils
  7. import 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 <- trumpColour
  16. turnCol <- turnColour
  17. let possible = filter (isAllowed trumpCol turnCol hand) hand
  18. c <- liftIO $ askIO (map getCard table) possible 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