SHARE
TWEET

Untitled

a guest Sep 12th, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module BlackJack where
  2.  
  3. import Cards
  4. import RunGame
  5.  
  6. import Test.QuickCheck hiding (shuffle)
  7.  
  8. aCard1 :: Card
  9. aCard1 = Card King Spades
  10. aCard2 :: Card
  11. aCard2 = Card Ace Spades
  12. aCard3 :: Card
  13. aCard3 = Card (Numeric 7) Hearts
  14.  
  15. aHand :: Hand
  16. aHand = [aCard2, aCard2]
  17.  
  18. hand2 :: Hand
  19. hand2 = [Card (Numeric 2) Hearts, Card Jack Spades]
  20.  
  21. sizeSteps :: [Int]
  22. sizeSteps = [ size hand2
  23.             , size (Card (Numeric 2) Hearts : (Card Jack Spades : []))
  24.             , size (Card Jack Spades : []) + 1
  25.             , size ([]) + 2
  26.             , 2
  27.             ]
  28.  
  29.  
  30. displayCard :: Card -> String
  31. displayCard (Card (Numeric n) suit) = show n ++ " of " ++ show suit
  32. displayCard (Card rank suit) = show rank ++ " of " ++ show suit
  33.  
  34. display :: Hand -> String
  35. display [] = ""
  36. --display [hand] = displayCard (hand)
  37. display (hand:hands) = displayCard hand ++ ", " ++ display(hands)
  38.  
  39. --set Ace to value 0 then go thouge and set value
  40.  
  41. valueCard :: Card -> Int
  42. valueCard (Card (Numeric n) suit) = n
  43. valueCard (Card Ace suit) = 0
  44. valueCard (Card _ suit) = 10
  45.  
  46. numberOfAce :: Hand -> Int
  47. numberOfAce [] = 0
  48. numberOfAce ((Card Ace _):cs)  = 1 + numberOfAce cs
  49. numberOfAce (_ :cs) = numberOfAce cs
  50.  
  51.  
  52. valueOfHand :: Hand -> Int
  53. valueOfHand [] = 0
  54. valueOfHand (c:cs) = valueCard + valueHand cs
  55.  
  56. value :: Hand -> Int
  57. value hand
  58.     | numberOfAce >= 2 = valueWithAceOne
  59.     | valueWithAceEleven <= 21 = valueWithAceEleven
  60.     |  Otherwise valueWithAceOne
  61.     Where
  62.           valueWithAceEleven = valueOfHand hand + (numberOfAce hand * 11)
  63.           valueWithAceOne = (valueOfHand hand) + numberOfAce hand
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top