test: create testing functions for average number of guesses over all possible targets
This commit is contained in:
parent
46ece35fde
commit
28532a3b3a
2 changed files with 21 additions and 4 deletions
20
Proj2.hs
20
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue