Copyright | (c) Ghais Issa 2021 |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Suit
- data Rank
- newtype Card = Card Int
- newCard :: Rank -> Suit -> Card
- randomCard :: RVar Card
- data Deck = Deck !Int ![Card]
- stdDeck :: Deck
- shuffleT :: Deck -> RVarT m Deck
- shuffle :: Deck -> RVar Deck
- draw :: [Int] -> Deck -> Maybe ([[Card]], Deck)
- draw_ :: [Int] -> Deck -> Maybe [[Card]]
- draw1 :: Int -> Deck -> Maybe ([Card], Deck)
- draw1_ :: Int -> Deck -> Maybe [Card]
- remove :: [Card] -> Deck -> Deck
Documentation
A card is represented as an int where the lower 4 bits representing the and the rest represents the rank ranging from 0-12.
Use newCard
to construct a new card.
randomCard :: RVar Card Source #
:: [Int] | a list of hand sizes. |
-> Deck | The deck. |
-> Maybe ([[Card]], Deck) | Nothing if the requested number of cards exceeds the deck size, or any of the hands is negative otherwise returns the hands and the remainder of the deck. |
Draw a list of cards from the deck and group them based on the list of hands provided.
Returns the grouped cards and the remaining deck.
Arguments that are negative or exceed the length of the deck return Nothing.
For instance, to simulate a two player Hold'em game, one might wish to draw two cards for each player, and five cards for the community:
>>>
deck <- runRVar (shuffle stdDeck) DevRandom
>>>
fst . fromJust $ draw [2,2,5] deck
[[Ace Club,Queen Club],[Four Diamond,Nine Club],[Jack Heart,King Diamond,Three Heart,Four Club,Two Diamond]]