diff --git a/Main.hs b/Main.hs index bbd5eec..711ac3f 100644 --- a/Main.hs +++ b/Main.hs @@ -39,7 +39,4 @@ toChord = fromJust . mapM toPitch . words -- | Prompt for a target and use guessTest to try to guess it. main :: IO () main = do - putStr "Target chord (3 pitches separated by spaces): " - hFlush stdout - text <- getLine - guessTest $ toChord text + putStr $ show avgGuesses diff --git a/Proj2.hs b/Proj2.hs index 84c4274..496aba1 100644 --- a/Proj2.hs +++ b/Proj2.hs @@ -54,6 +54,7 @@ module Proj2 GameState, initialGuess, nextGuess, + avgGuesses, ) where @@ -250,3 +251,22 @@ allChords = | note <- [minBound .. maxBound], octave <- [minBound .. maxBound] ] + +-- ==== TESTING =============================================================== + +guessTest :: [Pitch] -> Int +guessTest target = loop target guess other 1 + where + (guess, other) = initialGuess + +loop :: [Pitch] -> [Pitch] -> GameState -> Int -> Int +loop target guess other guesses + | answer == (3, 0, 0) = guesses + | otherwise = loop target guess' other' (guesses + 1) + where + answer = feedback target guess + (guess', other') = nextGuess (guess, other) answer + +avgGuesses = fromIntegral (sum results) / fromIntegral (length results) + where + results = map guessTest allChords