Added a deck of cards functionality
This commit is contained in:
parent
58f9a03123
commit
7a4ef79bf9
5 changed files with 76 additions and 15 deletions
46
lib/CardDeck.hs
Normal file
46
lib/CardDeck.hs
Normal file
|
@ -0,0 +1,46 @@
|
|||
module CardDeck (
|
||||
generateCards,
|
||||
generateShuffledCards
|
||||
) where
|
||||
|
||||
import Shuffle
|
||||
|
||||
-- Colors of cards
|
||||
data CardType = Clubs
|
||||
| Diamonds
|
||||
| Hearts
|
||||
| Spades
|
||||
| NoneType
|
||||
deriving (Show, Enum, Eq)
|
||||
|
||||
-- Values of cards
|
||||
data CardValue = Ace
|
||||
| Two
|
||||
| Three
|
||||
| Four
|
||||
| Five
|
||||
| Six
|
||||
| Seven
|
||||
| Eight
|
||||
| Nine
|
||||
| Ten
|
||||
| Jack
|
||||
| Queen
|
||||
| King
|
||||
| NoneValue
|
||||
deriving (Show, Enum, Eq)
|
||||
|
||||
-- A card has a type and a value
|
||||
type Card = (CardType, CardValue)
|
||||
|
||||
-- A deck of cards
|
||||
type Deck = [Card]
|
||||
|
||||
generateCards :: Deck
|
||||
generateCards = [(cType, cValue) | cType <- types, cValue <- values]
|
||||
where types = init $ enumFrom Clubs
|
||||
values = init $ enumFrom Ace
|
||||
|
||||
generateShuffledCards :: Deck
|
||||
generateShuffledCards = shuffle generateCards
|
||||
|
Reference in a new issue