Copyright | (c) 2017 Christopher A. Gorski |
---|---|
License | MIT |
Maintainer | Christopher A. Gorski <cgorski@cgorski.org> |
Safe Haskell | Safe |
Language | Haskell2010 |
The Game.Game.Poker module provides operations for five card poker.
- 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
>>>
pokerhand
PokerHand TwoPair [Five of Diamonds,Jack of Spades,Queen of Spades,Queen of Diamonds,Jack of Hearts]
>>>
typeOfPokerHand pokerhand
TwoPair
>>>
cardsOfPokerHand pokerhand
[Five of Diamonds,Jack of Spades,Queen of Spades,Queen of Diamonds,Jack of Hearts]
data PokerHandType Source #
The type of a PokerHand
.
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.
>>>
cardsOfPokerHand :: PokerHand -> [PlayingCard] Source #
Return the cards in a PokerHand
typeOfPokerHand :: PokerHand -> PokerHandType Source #
Return the PokerHandType
of a PokerHand
Building Hands
mkHand :: [PlayingCard] -> Maybe PokerHand Source #
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 Source #
Return True if a hand matches a specific PokerHandType. False otherwise.
Sets of Hand Types
allPossibleHands :: [[PlayingCard]] Source #
All possible hands of a full deck of playing cards
allRoyalFlush :: [[PlayingCard]] Source #
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]] Source #
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]] Source #
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]] Source #
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]] Source #
All flushes in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allStraight :: [[PlayingCard]] Source #
All straights in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allThreeOfAKind :: [[PlayingCard]] Source #
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]] Source #
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]] Source #
All pairs in a full deck of playing cards. The current implementation traverses the entire list of allPossibleHands, and is not efficient.
allHighCard :: [[PlayingCard]] Source #
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 Source #
Return a random hand that is not any other hand, also known as "High Card"
randomThreeOfAKind :: RandomGen g => Rand g PokerHand Source #
Return a random hand that is a Three of a Kind
randomFullHouse :: RandomGen g => Rand g PokerHand Source #
Return a random hand that is a Full House
randomFourOfAKind :: RandomGen g => Rand g PokerHand Source #
Return a random hand that is a Four of a Kind
randomStraightFlush :: RandomGen g => Rand g PokerHand Source #
Return a random hand that is a Straight Flush
randomRoyalFlush :: RandomGen g => Rand g PokerHand Source #
Return a random hand that is a Royal Flush
Additional Hand Building Functions
mkHighCard :: [PlayingCard] -> Maybe PokerHand Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
Verify that the best hand of a set of cards is a royal flush hand, and if so, return True. Otherwise, return False.