diff --git a/Proj2.hs b/Proj2.hs index 489760e..9c67d4a 100644 --- a/Proj2.hs +++ b/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 --