Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a5e9a715f | ||
|
|
5103cb7f0e | ||
|
|
5bd5fb0a25 | ||
|
|
1f28cc7cda | ||
|
|
bfdcfde6c9 | ||
|
|
28532a3b3a |
4 changed files with 30 additions and 5 deletions
5
Main.hs
5
Main.hs
|
|
@ -39,7 +39,4 @@ toChord = fromJust . mapM toPitch . words
|
||||||
-- | Prompt for a target and use guessTest to try to guess it.
|
-- | Prompt for a target and use guessTest to try to guess it.
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
putStr "Target chord (3 pitches separated by spaces): "
|
putStr $ show avgGuesses
|
||||||
hFlush stdout
|
|
||||||
text <- getLine
|
|
||||||
guessTest $ toChord text
|
|
||||||
|
|
|
||||||
20
Proj2.hs
20
Proj2.hs
|
|
@ -54,6 +54,7 @@ module Proj2
|
||||||
GameState,
|
GameState,
|
||||||
initialGuess,
|
initialGuess,
|
||||||
nextGuess,
|
nextGuess,
|
||||||
|
avgGuesses,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
|
@ -250,3 +251,22 @@ allChords =
|
||||||
| note <- [minBound .. maxBound],
|
| note <- [minBound .. maxBound],
|
||||||
octave <- [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
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,12 @@
|
||||||
# Spec
|
# Spec
|
||||||
|
## Best first guess
|
||||||
|
### All different
|
||||||
|
[C1, D2, E3]: 4.27
|
||||||
|
[A1, D2, G3]: 4.25
|
||||||
|
### Same notes
|
||||||
|
[D1, D2, D3]: 4.80
|
||||||
|
### Same octaves
|
||||||
|
[C2, D2, E2]: 4.34
|
||||||
## Tips to improve `nextGuess`
|
## Tips to improve `nextGuess`
|
||||||
The best results can be had by carefully choosing each guess so that it is most
|
The best results can be had by carefully choosing each guess so that it is most
|
||||||
likely to leave a small remaining list of possible targets. You can do this by
|
likely to leave a small remaining list of possible targets. You can do this by
|
||||||
|
|
|
||||||
2
justfile
2
justfile
|
|
@ -12,4 +12,4 @@ build:
|
||||||
|
|
||||||
# run musician
|
# run musician
|
||||||
run:
|
run:
|
||||||
./target/{{exec}}
|
time ./target/{{exec}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue