ofc-calc-haskell-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

Game.Combination

Description

Poker combination and its processing functions

Synopsis

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

Instances details
Eq Combination Source #

Description of Eq class for Combination.

In case if simple RankCombination - equality by name and rank; In case of complex PartCombination - by name, first part and second part;

Examples:

(RankCombination Pair $ Card Three Spades) == (RankCombination Pair $ Card Three Heart) = True
(RankCombination Set $ Card Three Spades) == (RankCombination Pair $ Card Three Heart) = False
(RankCombination Set $ Card Three Spades) == (RankCombination Straight $ Card Three Heart) = False
Instance details

Defined in Game.Combination

Ord Combination Source #

Description of Ord class for Combination.

In case if simple RankCombination - compare by name and rank; In case of complex PartCombination - by name, first part and second part;

Examples:

(RankCombination Pair $ Card Three Spades) compare (RankCombination Pair $ Card Three Heart) = EQ
(RankCombination Set $ Card Three Spades) compare (RankCombination Pair $ Card Three Heart) = GT
(RankCombination Set $ Card Three Spades) compare (RankCombination Straight $ Card Three Heart) = LT
Instance details

Defined in Game.Combination

Show Combination Source # 
Instance details

Defined in Game.Combination

Generic Combination Source # 
Instance details

Defined in Game.Combination

Associated Types

type Rep Combination :: Type -> Type #

FromJSON Combination Source # 
Instance details

Defined in Game.Combination

Methods

parseJSON :: Value -> Parser Combination

parseJSONList :: Value -> Parser [Combination]

ToJSON Combination Source # 
Instance details

Defined in Game.Combination

Methods

toJSON :: Combination -> Value

toEncoding :: Combination -> Encoding

toJSONList :: [Combination] -> Value

toEncodingList :: [Combination] -> Encoding

type Rep Combination Source # 
Instance details

Defined in Game.Combination

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}

data CombinationName Source #

Names of combinations enum

Instances

Instances details
Bounded CombinationName Source # 
Instance details

Defined in Game.Combination

Enum CombinationName Source # 
Instance details

Defined in Game.Combination

Eq CombinationName Source # 
Instance details

Defined in Game.Combination

Ord CombinationName Source # 
Instance details

Defined in Game.Combination

Show CombinationName Source # 
Instance details

Defined in Game.Combination

Generic CombinationName Source # 
Instance details

Defined in Game.Combination

Associated Types

type Rep CombinationName :: Type -> Type #

FromJSON CombinationName Source # 
Instance details

Defined in Game.Combination

Methods

parseJSON :: Value -> Parser CombinationName

parseJSONList :: Value -> Parser [CombinationName]

ToJSON CombinationName Source # 
Instance details

Defined in Game.Combination

Methods

toJSON :: CombinationName -> Value

toEncoding :: CombinationName -> Encoding

toJSONList :: [CombinationName] -> Value

toEncodingList :: [CombinationName] -> Encoding

type Rep CombinationName Source # 
Instance details

Defined in Game.Combination

type Rep CombinationName = D1 ('MetaData "CombinationName" "Game.Combination" "ofc-calc-haskell-0.1.0.0-inplace" 'False) (((C1 ('MetaCons "Kicker" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Pair" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TwoPairs" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Set" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Straight" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "Flush" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FullHouse" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "FourOfAKind" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "StraightFlush" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "RoyalFlush" 'PrefixI 'False) (U1 :: Type -> Type)))))