| Copyright | (c) 2017 Christopher A. Gorski |
|---|---|
| License | MIT |
| Maintainer | Christopher A. Gorski <cgorski@cgorski.org> |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Game.Game.Poker
Contents
Description
The Game.Game.Poker module provides operations for five card poker.
Synopsis
- data PokerHand
- data PokerHandType
- data AceRank
- cardsOfPokerHand :: PokerHand -> [PlayingCard]
- typeOfPokerHand :: PokerHand -> PokerHandType
- mkHand :: [PlayingCard] -> Maybe PokerHand
- isHand :: PokerHandType -> [PlayingCard] -> Bool
- allPossibleHands :: [[PlayingCard]]
- allRoyalFlush :: [[PlayingCard]]
- allStraightFlush :: [[PlayingCard]]
- allFourOfAKind :: [[PlayingCard]]
- allFullHouse :: [[PlayingCard]]
- allFlush :: [[PlayingCard]]
- allStraight :: [[PlayingCard]]
- allThreeOfAKind :: [[PlayingCard]]
- allTwoPair :: [[PlayingCard]]
- allPair :: [[PlayingCard]]
- allHighCard :: [[PlayingCard]]
- randomHighCard :: RandomGen g => Rand g PokerHand
- randomPair :: RandomGen g => Rand g PokerHand
- randomTwoPair :: RandomGen g => Rand g PokerHand
- randomThreeOfAKind :: RandomGen g => Rand g PokerHand
- randomStraight :: RandomGen g => Rand g PokerHand
- randomFlush :: RandomGen g => Rand g PokerHand
- randomFullHouse :: RandomGen g => Rand g PokerHand
- randomFourOfAKind :: RandomGen g => Rand g PokerHand
- randomStraightFlush :: RandomGen g => Rand g PokerHand
- randomRoyalFlush :: RandomGen g => Rand g PokerHand
- mkHighCard :: [PlayingCard] -> Maybe PokerHand
- mkPair :: [PlayingCard] -> Maybe PokerHand
- mkTwoPair :: [PlayingCard] -> Maybe PokerHand
- mkThreeOfAKind :: [PlayingCard] -> Maybe PokerHand
- mkStraight :: [PlayingCard] -> Maybe PokerHand
- mkFlush :: [PlayingCard] -> Maybe PokerHand
- mkFullHouse :: [PlayingCard] -> Maybe PokerHand
- mkFourOfAKind :: [PlayingCard] -> Maybe PokerHand
- mkStraightFlush :: [PlayingCard] -> Maybe PokerHand
- mkRoyalFlush :: [PlayingCard] -> Maybe PokerHand
- isHighCard :: [PlayingCard] -> Bool
- isPair :: [PlayingCard] -> Bool
- isTwoPair :: [PlayingCard] -> Bool
- isThreeOfAKind :: [PlayingCard] -> Bool
- isStraight :: [PlayingCard] -> Bool
- isFlush :: [PlayingCard] -> Bool
- isFullHouse :: [PlayingCard] -> Bool
- isFourOfAKind :: [PlayingCard] -> Bool
- isStraightFlush :: [PlayingCard] -> Bool
- isRoyalFlush :: [PlayingCard] -> Bool
Poker Hand Types
A poker hand. Constructors are hidden, so any hand encapsulated in this type can be considered a valid hand.
>>>deck <- evalRandIO $ shuffle $ (fullDeck :: [PlayingCard])>>>hand = draw1_ 5 deck>>>hand[Five of Diamonds,Jack of Spades,Queen of Spades,Queen of Diamonds,Jack of Hearts]
>>>pokerhand = fromJust $ mkHand hand>>>pokerhandPokerHand TwoPair [Five of Diamonds,Jack of Spades,Queen of Spades,Queen of Diamonds,Jack of Hearts]
>>>typeOfPokerHand pokerhandTwoPair
>>>cardsOfPokerHand pokerhand[Five of Diamonds,Jack of Spades,Queen of Spades,Queen of Diamonds,Jack of Hearts]
data PokerHandType #
The type of a PokerHand.
Constructors
| HighCard | |
| Pair | |
| TwoPair | |
| ThreeOfAKind | |
| Straight AceRank | |
| Flush | |
| FullHouse | |
| FourOfAKind | |
| StraightFlush AceRank | |
| RoyalFlush |
Instances
| Eq PokerHandType # | |
Defined in Game.Game.Poker Methods (==) :: PokerHandType -> PokerHandType -> Bool # (/=) :: PokerHandType -> PokerHandType -> Bool # | |
| Show PokerHandType # | |
Defined in Game.Game.Poker Methods showsPrec :: Int -> PokerHandType -> ShowS # show :: PokerHandType -> String # showList :: [PokerHandType] -> ShowS # | |
Indicates if a poker hand uses the Ace as a high card or a low card. AceLow is only used when an Ace is in a hand. Any hand without an Ace is considered AceHigh.
>>>
Instances
| Bounded AceRank # | |
| Enum AceRank # | |
| Eq AceRank # | |
| Ord AceRank # | |
| Show AceRank # | |
cardsOfPokerHand :: PokerHand -> [PlayingCard] #
Return the cards in a PokerHand
typeOfPokerHand :: PokerHand -> PokerHandType #
Return the PokerHandType of a PokerHand
Building Hands
mkHand :: [PlayingCard] -> Maybe PokerHand #
Given a list of cards, find the best hand in the set. If the number of cards is not equal to five, or there are duplicate cards, mkHand returns Nothing.
Hand Type Existence Checks
isHand :: PokerHandType -> [PlayingCard] -> Bool #
Return True if a hand matches a specific PokerHandType. False otherwise.
Sets of Hand Types
allPossibleHands :: [[PlayingCard]] #
All possible hands of a full deck of playing cards
allRoyalFlush :: [[PlayingCard]] #
All royal flushes in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allStraightFlush :: [[PlayingCard]] #
All straight flushes in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allFourOfAKind :: [[PlayingCard]] #
All four-of-a-kinds in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allFullHouse :: [[PlayingCard]] #
All full houses in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allFlush :: [[PlayingCard]] #
All flushes in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allStraight :: [[PlayingCard]] #
All straights in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allThreeOfAKind :: [[PlayingCard]] #
All three-of-a-kind in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allTwoPair :: [[PlayingCard]] #
All two pairs in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allPair :: [[PlayingCard]] #
All pairs in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allHighCard :: [[PlayingCard]] #
All high card hands in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
Random Hands
randomHighCard :: RandomGen g => Rand g PokerHand #
Return a random hand that is not any other hand, also known as "High Card"
randomPair :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Pair
randomTwoPair :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Two Pair
randomThreeOfAKind :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Three of a Kind
randomStraight :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Straight
randomFlush :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Flush
randomFullHouse :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Full House
randomFourOfAKind :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Four of a Kind
randomStraightFlush :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Straight Flush
randomRoyalFlush :: RandomGen g => Rand g PokerHand #
Return a random hand that is a Royal Flush
Additional Hand Building Functions
mkHighCard :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a high card hand,
and if so, return a PokerHand. Otherwise, return Nothing.
mkPair :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a pair hand,
and if so, return a PokerHand. Otherwise, return Nothing.
mkTwoPair :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a two pair,
and if so, return a PokerHand. Otherwise, return Nothing.
mkThreeOfAKind :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a three-of-a-kind hand,
and if so, return a PokerHand. Otherwise, return Nothing.
mkStraight :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a straight hand,
and if so, return a PokerHand. Otherwise, return Nothing.
mkFlush :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a flush hand,
and if so, return a PokerHand. Otherwise, return Nothing.
mkFullHouse :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a full house hand,
and if so, return a PokerHand. Otherwise, return Nothing.
mkFourOfAKind :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a four-of-a-kind hand,
and if so, return a PokerHand. Otherwise, return Nothing.
mkStraightFlush :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a straight flush hand,
and if so, return a PokerHand. Otherwise, return Nothing.
mkRoyalFlush :: [PlayingCard] -> Maybe PokerHand #
Verify that the best hand of a set of cards is a royal flush hand,
and if so, return a PokerHand. Otherwise, return Nothing.
Additional Hand Type Existence Checks
isHighCard :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a high card hand, and if so, return True. Otherwise, return False.
isPair :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a pair hand, and if so, return True. Otherwise, return False.
isTwoPair :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a two pair hand, and if so, return True. Otherwise, return False.
isThreeOfAKind :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a three-of-a-kind hand, and if so, return True. Otherwise, return False.
isStraight :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a straight hand, and if so, return True. Otherwise, return False.
isFlush :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a flush hand, and if so, return True. Otherwise, return False.
isFullHouse :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a full house hand, and if so, return True. Otherwise, return False.
isFourOfAKind :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a four-of-a-kind hand, and if so, return True. Otherwise, return False.
isStraightFlush :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a straight flush hand, and if so, return True. Otherwise, return False.
isRoyalFlush :: [PlayingCard] -> Bool #
Verify that the best hand of a set of cards is a royal flush hand, and if so, return True. Otherwise, return False.