Safe Haskell | None |
---|---|
Language | Haskell2010 |
Poker combination and its processing functions
Synopsis
- data Combination
- = RankCombination {
- name :: CombinationName
- rank :: Card
- | PartCombination { }
- = RankCombination {
- getOccurrences :: [Card] -> OccurrencesCounter
- parseSequence :: [Card] -> Either String Combination
- parsePartHand :: OccurrencesCounter -> Either String Combination
- parseCombination :: [Card] -> Either String Combination
- data CombinationName
- = Kicker
- | Pair
- | TwoPairs
- | Set
- | Straight
- | Flush
- | FullHouse
- | FourOfAKind
- | StraightFlush
- | RoyalFlush
Documentation
data Combination Source #
This type represents a poker combination. | It is divided by two constructors: for simple combinations (pair, set etc.) | and for combinations with multiple items (two pairs, full house)
Instances
getOccurrences :: [Card] -> OccurrencesCounter Source #
This function gets a list of cards and returns a list of tuples. First element of which contains certain card, and second element contains number of occurences.
Function takes the head of the list and search for occurrences of its card in the tail. Then, recursively calls itself for tail with that card removed from it.
Examples:
getOccurrences [Card
{value =Ace
, suit =Spades
},Card
{value =Jack
, suit =Clubs
},Card
{value =Ace
, suit = 'Hearts} ] = [(Card {value = Ace, suit = Spades},2),(Card {value = Jack, suit = Clubs},1)]
parseSequence :: [Card] -> Either String Combination Source #
This function parses sequences in cards line returns a combination, wrapped with Right
,
or string err msg wrapped with Left
.
The input is list of cards - [Card
].
Examples:
parseSequence [ (Card
{value =Ace
, suit =Spades
}, 2), (Card
{value =King
, suit =Clubs
}, 2) ] =Right
PartCombination
TwoPairs
(Card
{value =Ace
, suit =Spades
) (Card
{value =King
, suit =Clubs
})
parsePartHand :: OccurrencesCounter -> Either String Combination Source #
This function parses occurences data and returns a combination, wrapped with Right
,
or string err msg wrapped with Left
.
The input is list of tuples - [(Card
, Int
)], where first element is a card and seconds is number of its occurrences.
Examples:
parsePartHand [Card
{value =Ace
, suit =Spades
},Card
{value =Jack
, suit =Clubs
},Card
{value =Ten
, suit =Clubs
},Card
{value =Queen
, suit = 'Hearts},Card
{value =King
, suit = 'Hearts}, ] =Right
RankCombination
Straight
Card
{value =Ace
, suit =Spades
}
parseCombination :: [Card] -> Either String Combination Source #
data CombinationName Source #
Names of combinations enum