refactor: inline functions in feedback for clarity
This commit is contained in:
parent
96b7053c5d
commit
de3a7abafe
1 changed files with 7 additions and 10 deletions
17
Proj2.hs
17
Proj2.hs
|
|
@ -130,26 +130,23 @@ toPitch _ = Nothing
|
|||
-- performer to decide on the best guess to make each turn
|
||||
--
|
||||
feedback :: [Pitch] -> [Pitch] -> (Int, Int, Int)
|
||||
feedback target guess = (length correctPitches, correctNotes, correctOctaves)
|
||||
feedback target guess = (pitches, notes, octaves)
|
||||
where
|
||||
-- since pitches are unique in a guess,
|
||||
-- we can use set math to count how many are correct
|
||||
targetSet = S.fromList target
|
||||
guessSet = S.fromList guess
|
||||
|
||||
correctPitches = S.intersection targetSet guessSet
|
||||
|
||||
newTarget = S.toList $ S.difference targetSet correctPitches
|
||||
newGuess = S.toList $ S.difference guessSet correctPitches
|
||||
|
||||
(targetNotes, guessNotes) = (map note newTarget, map note newGuess)
|
||||
(targetOctaves, guessOctaves) = (map octave newTarget, map octave newGuess)
|
||||
pitchSet = S.intersection targetSet guessSet
|
||||
pitches = length pitchSet
|
||||
|
||||
-- since notes and octaves are not unique in a guess,
|
||||
-- we can compare the guess to all possible permutations of the target
|
||||
-- and count the pairwise note/octave matches
|
||||
correctNotes = matches targetNotes guessNotes
|
||||
correctOctaves = matches targetOctaves guessOctaves
|
||||
targetNoPitches = S.toList $ S.difference targetSet pitchSet
|
||||
guessNoPitches = S.toList $ S.difference guessSet pitchSet
|
||||
notes = matches (map note targetNoPitches) (map note guessNoPitches)
|
||||
octaves = matches (map octave targetNoPitches) (map octave guessNoPitches)
|
||||
|
||||
-- TODO: comment me
|
||||
--
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue