diff --git a/Main.hs b/Main.hs index e7309dd..4596dfb 100644 --- a/Main.hs +++ b/Main.hs @@ -10,13 +10,11 @@ import Data.List import Data.Maybe import Proj2 - -- | Guess the given target, counting and showing the guesses. guessTest :: [Pitch] -> IO () guessTest target = do - let (guess,other) = initialGuess - loop target guess other 1 - + let (guess, other) = initialGuess + loop target guess other 1 -- | Given a target and guess and a guess number, continue guessing -- until the right target is guessed. @@ -25,19 +23,17 @@ loop target guess other guesses = do putStrLn $ "Your guess #" ++ show guesses ++ ": " ++ show guess let answer = feedback target guess putStrLn $ " My answer: " ++ show answer - if answer == (3,0,0) + if answer == (3, 0, 0) then do putStrLn $ "You got it in " ++ show guesses ++ " guesses!" else do - let (guess',other') = nextGuess (guess,other) answer - loop target guess' other' (guesses+1) - + let (guess', other') = nextGuess (guess, other) answer + loop target guess' other' (guesses + 1) -- | Parse a string containing a number of space-separated pitches to produce -- a list of pitches. Error if any of the pitches can't be parsed. toChord :: String -> [Pitch] -toChord = (fromJust . mapM toPitch . words) - +toChord = fromJust . mapM toPitch . words -- | Prompt for a target and use guessTest to try to guess it. main :: IO () diff --git a/Proj2.hs b/Proj2.hs index 64e3977..2292d26 100644 --- a/Proj2.hs +++ b/Proj2.hs @@ -1,26 +1,31 @@ ---Implement your solution here ---SEE THE PROJECT CODING GUIDELINES ON THE LMS FOR DETAILS OF ---THE CRITERIA THAT WILL BE EMPLOYED IN ASSESSING YOUR CODE. ---Please DELETE THIS WHOLE COMMENT, and write your own. +-- -module Proj2 (Pitch, toPitch, feedback, - GameState, initialGuess, nextGuess) where +module Proj2 + ( Pitch, + toPitch, + feedback, + GameState, + initialGuess, + nextGuess, + ) +where type GameState = () -data Pitch = Pitch { note :: Char - , octave :: Int - } deriving (Eq) +data Pitch = Pitch + { note :: Char, + octave :: Int + } + deriving (Eq) instance Show Pitch where - show (Pitch note octave) = [note] ++ show octave - + show (Pitch note octave) = note : show octave toPitch :: String -> Maybe Pitch toPitch _ = Just (Pitch 'A' 1) feedback :: [Pitch] -> [Pitch] -> (Int, Int, Int) -feedback _ _ = (0,0,0) +feedback _ _ = (0, 0, 0) initialGuess :: ([Pitch], GameState) initialGuess = ([Pitch 'A' 1], ())