I am writing a Cardguess Game, where user sets the answer and lets the PC guess. For my project, the input card number is 2.
Then, I need to write the cardguess algorithm. I have created the card module.
data Suit = Club | Diamond | Heart | Spade
deriving (Eq, Ord, Bounded, Enum)
suitchars = "CDHS"
data Rank =
R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 |
Jack | Queen | King | Ace
deriving (Eq, Ord, Bounded, Enum)
rankchars = "23456789TJQKA"
data Card = Card {suit::Suit, rank::Rank}
deriving (Eq, Bounded)
instance Ord Card where
compare (Card s1 r1) (Card s2 r2) =
let suitorder = compare s1 s2
in if suitorder == EQ then compare r1 r2 else suitorder
instance Enum Card where
fromEnum (Card s r) = (fromEnum s)*13 + (fromEnum r)
toEnum n = (Card s r)
where s = toEnum (n `div` 13)
r = toEnum (n `mod` 13)
and my strategy is to separate both Suit and Rank into two parts. initial guess could be Card Club R5 , Card Heart Jack
Then I will be given the feedback, and, according to it, I will try nextGuess, so on so far, till getting the right answer.
I have written the initialGuess function.
i put the remaining cards in the GameState.
initialGuess :: Int -> ([Card], GameState)
initialGuess card_number
| card_number == 2 = ((Card Club R5):(Card Heart J),cardDeck)
and now, I need to write the nextGuess code.
nextGuess :: ([Card],GameState) -> (Int,Int,Int,Int,Int) ->([Card],GameState)
(Int,Int,Int,Int,Int) is the feedback value.
How can i represent the first parameter ([Card],GameState), which means the previous guess cards and previous GameState.
([Card],GameState)”. I don't understand what you mean by this. Please clarify. The first parameter is a representation of “the previous guess cards and previousGameState”. - dave4420nextGuess. As far asnextGuessis concerned it's just a parameter, same ascard_numberis forinitialGuess. Is your question really about how to callnextGuess? - dave4420