java-poker-0.1.2.0: The etude of the Haskell programming

Safe HaskellSafe
LanguageHaskell2010

Game.Poker.Hands

Synopsis

Documentation

data Hand Source

Constrained cards in hand

>>> :type fromHand
fromHand :: Hand -> [Card]

toHand :: [Card] -> Maybe Hand Source

Cards to Hard

>>> toHand allCards
Nothing
>>> fmap (length . fromHand) (toHand $ take 5 allCards)
Just 5

pokerHand :: Hand -> (PokerHand, Card) Source

Detect poker hand and return strength Card

>>> let sameNum = filter ((==14) . cardNumber) allCards
>>> let sameSuit = filter ((==Hearts) . cardSuit) allCards
>>> pokerHand (Hand $ take 5 sameSuit)
(StraightFlush,H6_)
>>> let buta = take 2 allCards ++ (take 2 $ drop 17 allCards) ++ [last allCards]
>>> pokerHand (Hand buta)
(HighCards,SA_)

straightHint :: Hand -> Maybe Card Source

Check straight in Hand

>>> straightHint $ Hand (take 5 allCards)
Just H6_
>>> straightHint $ Hand (take 5 $ drop 8 allCards)
Just HA_
>>> straightHint $ Hand (take 2 $ allCards)
Nothing

flushHint :: Hand -> Maybe Card Source

Check flush in Hand

>>> flushHint $ Hand (take 5 $ filter (\x -> cardSuit x == Hearts) allCards )
Just H6_
>>> flushHint $ Hand (take 5 $ filter (\x -> cardNumber x == 2) allCards )
Nothing

nOfKindHint :: Int -> Hand -> Maybe [[Card]] Source

n of Kind in Hand

>>> let treeCards = take 3 $ filter ((==2) . cardNumber) $ allCards
>>> let twoCards = take 2 $ filter ((==10) . cardNumber) $ allCards
>>> let fullhouse = toHand $ treeCards ++ twoCards
>>> fullhouse >>= nOfKindHint 2
Just [[H10,D10]]
>>> fullhouse >>= nOfKindHint 3
Just [[H2_,D2_,C2_]]
>>> fullhouse >>= nOfKindHint 4
Nothing

fourOfAKind :: Hand -> Maybe (PokerHand, Card) Source

Detect FourOfAKind and return strongest Card

>>> let sameNum = filter ((==4) . cardNumber) allCards
>>> let sameSuit = filter ((==Spades) . cardSuit) allCards
>>> fourOfAKind $ Hand (take 4 sameNum ++ take 1 sameSuit)
Just (FourOfAKind,S4_)
>>> fourOfAKind $ Hand (take 5 sameSuit)
Nothing

fullHouse :: Hand -> Maybe (PokerHand, Card) Source

Detect fullHouse and return strongest Card

>>> let sameNum = filter ((==9) . cardNumber) allCards
>>> let sameNum' = filter ((==10) . cardNumber) allCards
>>> let sameSuit = filter ((==Spades) . cardSuit) allCards
>>> fullHouse $ Hand (take 2 sameNum ++ take 3 sameNum')
Just (FullHouse,C10)
>>> fullHouse $ Hand (take 3 sameNum ++ take 2 sameNum')
Just (FullHouse,C9_)
>>> fullHouse $ Hand (take 2 sameNum ++ take 3 sameSuit)
Nothing
>>> fullHouse $ Hand (take 5 sameSuit)
Nothing

flush :: Hand -> Maybe (PokerHand, Card) Source

Detect Flush and return strongest Card

>>> flush $ Hand (take 5 $ filter ((==Hearts) . cardSuit ) allCards)
Just (Flush,H6_)
>>> flush $ Hand (take 5 $ filter ((<= 3) . cardNumber) allCards)
Nothing

straight :: Hand -> Maybe (PokerHand, Card) Source

Detect Straight and return strongest Card

>>> straight $ Hand (take 5 $ filter ((==Hearts) . cardSuit) allCards)
Just (Straight,H6_)
>>> straight $ Hand (take 5 $ filter (even . cardNumber) allCards)
Nothing

threeOfAKind :: Hand -> Maybe (PokerHand, Card) Source

Detect ThreeOfAKind and return strongest Card

>>> let sameNum = filter ((==4) . cardNumber) allCards
>>> let sameSuit = filter ((==Spades) . cardSuit) allCards
>>> threeOfAKind $ Hand (take 3 sameNum ++ take 2 sameSuit)
Just (ThreeOfAKind,C4_)
>>> threeOfAKind $ Hand (take 5 sameSuit)
Nothing

twoPair :: Hand -> Maybe (PokerHand, Card) Source

Detect TwoPair and return strongest Card

>>> let sameNum = filter ((==9) . cardNumber) allCards
>>> let sameNum' = filter ((==10) . cardNumber) allCards
>>> let sameSuit = filter ((==Spades) . cardSuit) allCards
>>> twoPair $ Hand (take 2 sameNum ++ take 2 sameNum' ++ take 1 sameSuit)
Just (TwoPair,D10)
>>> twoPair $ Hand (take 2 sameNum ++ take 3 sameSuit)
Nothing
>>> twoPair $ Hand (take 5 sameSuit)
Nothing

onePair :: Hand -> Maybe (PokerHand, Card) Source

Detect onePair and return strongest Card

>>> let sameNum = filter ((==9) . cardNumber) allCards
>>> let sameSuit = filter ((==Spades) . cardSuit) allCards
>>> onePair $ Hand (take 2 sameNum ++ take 3 sameSuit)
Just (OnePair,D9_)
>>> onePair $ Hand (take 5 sameSuit)
Nothing

type Deck = [Card] Source

drawHand :: Deck -> DiscardList -> Hand -> Maybe (Hand, Deck) Source

Draw cards to make new hand from Deck Return a new Hand and Deck if its possible.

>>> 

getHand :: Deck -> Maybe (Hand, Deck) Source

Get hand from deck(Yamafuda)

>>> let Just (hand, newDeck) = getHand allCards
>>> hand
Hand {fromHand = [H2_,H3_,H4_,H5_,H6_]}
>>> let Just (_, newDeck') = getHand newDeck
>>> take 8 newDeck'
[HQ_,HK_,HA_,D2_,D3_,D4_,D5_,D6_]
>>> getHand allCards >>= return . snd >>= getHand >>= return . take 8 . snd
Just [HQ_,HK_,HA_,D2_,D3_,D4_,D5_,D6_]

getDiscardList :: Hand -> IO (Maybe DiscardList) Source

Get discardList(Sutefuda) from hand

toIntList :: String -> Maybe [Int] Source

String to [Int] for parse user inputs

>>> toIntList "1234"
Just [1,2,3,4]
>>> toIntList "4019"
Just [4,0,1,9]
>>> toIntList "z4q01"
Nothing
>>> toIntList ""
Just []

selectByIndexes :: [a] -> [Int] -> Maybe [a] Source

Get cards by indexes

>>> selectByIndexes "12345" [1..3]
Just "123"
>>> selectByIndexes "12345" [10]
Nothing

straightFlush :: Hand -> Maybe (PokerHand, Card) Source

Detect StraightFlush and return strongest Card

>>> straightFlush $ Hand (take 5 $ filter ((==Hearts) . cardSuit) allCards)
Just (StraightFlush,H6_)
>>> straightFlush $ Hand (take 5 $ filter (\x -> cardSuit x == Hearts && even (cardNumber x)) allCards)
Nothing
>>> let sameSuit = filter ((==Hearts) . cardSuit) allCards
>>> let sameSuit' = filter ((==Spades) . cardSuit) allCards
>>> straightFlush $ Hand (take 3 sameSuit ++ take 2 (drop 3 sameSuit'))
Nothing
>>> straightFlush $ Hand (take 5 $ filter (even . cardNumber) allCards)
Nothing

judgeVictory :: (PokerHand, Card) -> (PokerHand, Card) -> Ordering Source

Judge victory you and AI

>>>