Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module BlackJack where
- import Cards
- import RunGame
- import Test.QuickCheck hiding (shuffle)
- aCard1 :: Card
- aCard1 = Card King Spades
- aCard2 :: Card
- aCard2 = Card Ace Spades
- aCard3 :: Card
- aCard3 = Card (Numeric 7) Hearts
- aHand :: Hand
- aHand = [aCard2, aCard2]
- hand2 :: Hand
- hand2 = [Card (Numeric 2) Hearts, Card Jack Spades]
- sizeSteps :: [Int]
- sizeSteps = [ size hand2
- , size (Card (Numeric 2) Hearts : (Card Jack Spades : []))
- , size (Card Jack Spades : []) + 1
- , size ([]) + 2
- , 2
- ]
- displayCard :: Card -> String
- displayCard (Card (Numeric n) suit) = show n ++ " of " ++ show suit
- displayCard (Card rank suit) = show rank ++ " of " ++ show suit
- display :: Hand -> String
- display [] = ""
- --display [hand] = displayCard (hand)
- display (hand:hands) = displayCard hand ++ ", " ++ display(hands)
- --set Ace to value 0 then go thouge and set value
- valueCard :: Card -> Int
- valueCard (Card (Numeric n) suit) = n
- valueCard (Card Ace suit) = 0
- valueCard (Card _ suit) = 10
- numberOfAce :: Hand -> Int
- numberOfAce [] = 0
- numberOfAce ((Card Ace _):cs) = 1 + numberOfAce cs
- numberOfAce (_ :cs) = numberOfAce cs
- valueOfHand :: Hand -> Int
- valueOfHand [] = 0
- valueOfHand (c:cs) = valueCard + valueHand cs
- value :: Hand -> Int
- value hand
- | numberOfAce >= 2 = valueWithAceOne
- | valueWithAceEleven <= 21 = valueWithAceEleven
- | Otherwise valueWithAceOne
- Where
- valueWithAceEleven = valueOfHand hand + (numberOfAce hand * 11)
- valueWithAceOne = (valueOfHand hand) + numberOfAce hand
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement