module Player where import qualified Data.List as L import Card (Card) import qualified Card as C data Player = Player { name :: String , penalty :: Integer , cards :: [Card] } -- | Update `i`-th player in `ps` to `p`. update :: [Player] -> Int -> Player -> [Player] update ps i p = let (left, right) = splitAt i ps in left ++ [p] ++ (tail right) -- | Same player after shedding card specified. shed :: Player -> Card -> Player shed (Player n p cs) c = Player n p $ L.delete c cs -- | Same player after drawing cards specified. draw :: Player -> [Card] -> Player draw (Player n p cs) cs' = Player n p $ L.sort (cs' ++ cs) -- | Show player's cards, e.g. "1. Spade 2" showCards :: Player -> String showCards (Player _ _ cs) = unlines $ zipWith (\i c -> (show i) ++ ". " ++ C.showCard c) [1..] cs