Skip to content

Commit

Permalink
Add ways to peek at hole card for insurance and dealer bj checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick McLaughlin committed Apr 20, 2012
1 parent 2b26aee commit 94b0183
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
14 changes: 14 additions & 0 deletions cards.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Cards
, multiDeck
, shuffle
, shuffleIO
, aceInTheHole
, tenInTheHole
, Card(..)
, DownCard(..)
, Suit(..)
Expand Down Expand Up @@ -101,3 +103,15 @@ shuffle (Deck d) g = Deck $ shuffle' d (length d) g

shuffleIO :: StdDeck -> IO StdDeck
shuffleIO d = liftM (shuffle d) newStdGen

-- Legal ways to peek at the downcard
-- Make sure to 'turn' it still
aceInTheHole :: DownCard -> Bool
aceInTheHole (DownCard c) = isAce c
where isAce (Card Ace _) = True
isAce _ = False

tenInTheHole :: DownCard -> Bool
tenInTheHole (DownCard c) = isTen c
where isTen (Card r _) | r >= Ten = True
| otherwise = False
17 changes: 16 additions & 1 deletion dealer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ dealDealer d = let
dealDealerS :: Deck d => State d DealerHand
dealDealerS = liftS dealDealer

revealHoleCard :: Deck d => DealerHand -> d -> (Hand, d)
revealHoleCard (DealerHand a b) d = let
(a', d') = turn a d
h = hand [a', b]
in (h, d)

revealHoleCardS :: Deck d => DealerHand -> State d Hand
revealHoleCardS = liftS . revealHoleCard

-- Dealer only hits or stands
data DealerAction = Hit | Stand

Expand All @@ -35,4 +44,10 @@ standS17 :: DealerStrategy
standS17 = act . handTotal
where act (HandValue Bust _) = Stand
act (HandValue _ n) | n < 18 = Hit
| n >= 18 = Stand
| n >= 18 = Stand

offerInsurance :: DealerHand -> Bool
offerInsurance (DealerHand _ c) = isTen c
where isTen (Card r _) | r == Ace = False
| r >= Ten = True
| otherwise = False
7 changes: 2 additions & 5 deletions hands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ data DealerHand = DealerHand DownCard Card
instance Show DealerHand where
show (DealerHand _ c) = "DealerHand " ++ show c

data HandStatus = Play
| Done
data HandStatus = Play | Done
deriving (Show)

data HandType = Hard
| Soft
| Bust
data HandType = Hard | Soft | Bust
deriving (Show, Eq)

data HandValue = HandValue HandType Int
Expand Down

0 comments on commit 94b0183

Please sign in to comment.