diff options
author | Frederick Yin <fkfd@fkfd.me> | 2023-01-09 15:24:25 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2023-01-09 15:24:25 +0800 |
commit | cf97c134b2bff6672171ac05d05b399085f9ad3c (patch) | |
tree | 0535e60d3dc789573ba77ebbdf9414af5d6e7b3a /Game.hs | |
parent | 0a14130d8da78855a8d73d6d255dee060565df55 (diff) |
Allow regular card once attack is done; Auto mode
Diffstat (limited to 'Game.hs')
-rw-r--r-- | Game.hs | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -33,13 +33,14 @@ beginTurn game@(Game plyrs pidx att dir prev stock disc) = do putStrLn $ replicate 80 '-' putStrLn $ P.name player ++ "'s turn (input 0 to skip turn and draw card)" - putStrLn $ P.showCards player prev + putStrLn $ P.showCards player prev att putStrLn $ "Stock: " ++ (show $ length stock) ++ ", Discard: " ++ (show $ length disc) putStrLn $ "Current attack: " ++ show att putStrLn $ "Prev card: " ++ C.showCard prev - decision <- prompt game + -- decision <- prompt game + let decision = auto game game' <- case decision of Nothing -> drawAndSkip game Just card -> shedAndContinue card game @@ -112,12 +113,20 @@ prompt game@(Game plyrs pidx att _ prev _ _) = do prompt game else do let card = cards !! cardIdx - if C.isValid prev card + if C.isValid prev att card then return $ Just card else do putStrLn "You cannot play this card, try again" prompt game +-- | Make an automated decision to draw/shed card. +auto :: Game -> Maybe Card +auto game@(Game plyrs pidx att _ prev _ _) = + if null validCards + then Nothing + else Just (head validCards) + where validCards = filter (C.isValid prev att) $ P.cards (plyrs !! pidx) + -- | Deal c cards to each player in game. dealCards :: Int -> Game -> Game dealCards c game@(Game plyrs _ _ _ _ stock disc) |