SHARE
TWEET

Untitled

a guest Jan 16th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data Suit = Club | Diamond | Heart | Spade
  2.       deriving (Eq, Ord, Bounded, Enum)
  3.  
  4. suitchars = "CDHS"
  5.  
  6. data Rank =
  7.     R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 |
  8.     Jack | Queen | King | Ace
  9.          deriving (Eq, Ord, Bounded, Enum)
  10.  
  11. rankchars = "23456789TJQKA"
  12.  
  13. data Card = Card {suit::Suit, rank::Rank}
  14.       deriving (Eq, Bounded)
  15.  
  16. instance Ord Card where
  17.     compare (Card s1 r1) (Card s2 r2) =
  18.         let suitorder = compare s1 s2
  19.             in  if suitorder == EQ then compare r1 r2 else suitorder
  20.  
  21. instance Enum Card where
  22.     fromEnum (Card s r) = (fromEnum s)*13 + (fromEnum r)
  23.     toEnum n = (Card s r)
  24.      where s = toEnum (n `div` 13)
  25.            r = toEnum (n `mod` 13)
  26.    
  27. initialGuess :: Int -> ([Card], GameState)
  28. initialGuess card_number
  29.      | card_number == 2   = ((Card Club R5):(Card Heart J),cardDeck)
  30.    
  31. nextGuess :: ([Card],GameState) -> (Int,Int,Int,Int,Int) ->([Card],GameState)
  32.    
  33. initialGuess card_number
  34.      | card_number == 2   = ((Card Club R5):(Card Heart J),cardDeck)
  35.    
  36. initialGuess card_number
  37.      | card_number == 2   = (Card Club R5 : Card Heart J : [], cardDeck)
  38.    
  39. initialGuess card_number
  40.      | card_number == 2   = ([Card Club R5, Card Heart J], cardDeck)
  41.    
  42. instance Ord Card where
  43.     compare (Card s1 r1) (Card s2 r2) =
  44.         let suitorder = compare s1 s2
  45.             in  if suitorder == EQ then compare r1 r2 else suitorder
  46.    
  47. instance Ord Card where
  48.     compare (Card s1 r1) (Card s2 r2) = compare s1 s2 `mappend` compare r1 r2
  49.    
  50. data Card = Card {suit::Suit, rank::Rank}
  51.       deriving (Eq, Ord, Bounded)
  52.    
  53. startGuessing guesses state = do
  54.   feedBack <- readFeedback
  55.   let (newGuess, newState) = nextGuess (guesses, state) feedback
  56.   startGuessing (guesses ++ newGuess) newState
  57.  
  58. main = do
  59.   let (guesses, state) = initialGuess 2      
  60.   startGuessing guesses state
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