style: format code
This commit is contained in:
parent
f49eba9676
commit
3654485f23
2 changed files with 23 additions and 22 deletions
14
Main.hs
14
Main.hs
|
|
@ -10,14 +10,12 @@ 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
|
||||
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.
|
||||
loop :: [Pitch] -> [Pitch] -> GameState -> Int -> IO ()
|
||||
|
|
@ -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 ()
|
||||
|
|
|
|||
29
Proj2.hs
29
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], ())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue