|
- module AI.Human where
-
- import Control.Monad.Trans (liftIO)
-
- import Player
- import Pile
- import Card
- import Utils
- import Render
-
- data Human = Human { getTeam :: Team
- , getHand :: Hand }
- deriving Show
-
- instance Player Human where
- team = getTeam
- hand = getHand
- chooseCard p table _ hand = do
- trumpCol <- trumpColour
- turnCol <- turnColour
- let possible = filter (isAllowed trumpCol turnCol hand) hand
- c <- liftIO $ askIO (map getCard table) possible hand
- return $ (c, p)
-
- askIO :: [Card] -> [Card] -> [Card] -> IO Card
- askIO table possible hand = do
- putStrLn "Your hand"
- render hand
- putStrLn "These options are possible"
- render possible
- putStrLn "These cards are on the table"
- render table
- idx <- query
- "Which card do you want to play? Give the index of the card"
- if idx >= 0 && idx < length possible
- then return $ possible !! idx
- else askIO table possible hand
|