From 28532a3b3a277205099a01352caca15475139cee Mon Sep 17 00:00:00 2001 From: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:39:10 +1100 Subject: [PATCH 1/2] test: create testing functions for average number of guesses over all possible targets --- Main.hs | 5 +---- Proj2.hs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) 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 1b4ba1e..5ddf200 100644 --- a/Proj2.hs +++ b/Proj2.hs @@ -51,6 +51,7 @@ module Proj2 GameState, initialGuess, nextGuess, + avgGuesses, ) where @@ -239,3 +240,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 From bfdcfde6c98490aea035f46f983d1026da79e7d2 Mon Sep 17 00:00:00 2001 From: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:39:22 +1100 Subject: [PATCH 2/2] build: add command time to justfile --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index d0b0bdf..de6de60 100644 --- a/justfile +++ b/justfile @@ -12,4 +12,4 @@ build: # run musician run: - ./target/{{exec}} + time ./target/{{exec}}