test: create testing functions for average number of guesses over all possible targets

This commit is contained in:
wi11-holdsworth 2025-10-07 19:39:10 +11:00
parent e16c6bbf7d
commit 1f28cc7cda
2 changed files with 21 additions and 4 deletions

View file

@ -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