diff options
author | Frederick Yin <fkfd@fkfd.me> | 2023-01-05 20:58:40 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2023-01-05 20:58:40 +0800 |
commit | 8642b92029e8e7072d18fa04f90ee59f7ac3d933 (patch) | |
tree | a5b40e22f48e5765f983c4312e9e2c396085e4e4 /Player.hs | |
parent | 01148a563d4739573b08f7a2ee80078a90232fd6 (diff) |
Player.shed, draw, showCards
Diffstat (limited to 'Player.hs')
-rw-r--r-- | Player.hs | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1,9 +1,23 @@ module Player where +import qualified Data.List as L import Card (Card) -import qualified Card +import qualified Card as C data Player = Player { name :: String , penalty :: Integer , cards :: [Card] } + +-- | 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 card specified. +draw :: Player -> Card -> Player +draw (Player n p cs) c = Player n p $ L.sort (c: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 |