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 algorit
As I don't understand your question, and you are a beginner, I am going to nitpick on some other areas of your post.
You have
initialGuess card_number
| card_number == 2 = ((Card Club R5):(Card Heart J),cardDeck)
Accepting that you only need initialGuess 2
to work for now, you have the list syntax wrong. You mean either
initialGuess card_number
| card_number == 2 = (Card Club R5 : Card Heart J : [], cardDeck)
or
initialGuess card_number
| card_number == 2 = ([Card Club R5, Card Heart J], cardDeck)
They mean the same thing, but the latter is clearer.
You have
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
If you import Data.Monoid
, you can write this more simply as
instance Ord Card where
compare (Card s1 r1) (Card s2 r2) = compare s1 s2 `mappend` compare r1 r2
But better is to leave it out and ask the compiler to write it for you instead:
data Card = Card {suit::Suit, rank::Rank}
deriving (Eq, Ord, Bounded)
The generated Ord
instance uses lexicographical ordering, as you require.
Hard to read your mind here, but maybe you want something like this:
startGuessing guesses state = do
feedBack <- readFeedback
let (newGuess, newState) = nextGuess (guesses, state) feedback
startGuessing (guesses ++ newGuess) newState
main = do
let (guesses, state) = initialGuess 2
startGuessing guesses state