refactor: inline functions in feedback for clarity

This commit is contained in:
wi11-holdsworth 2025-10-01 14:32:39 +10:00
parent 96b7053c5d
commit de3a7abafe

View file

@ -130,26 +130,23 @@ toPitch _ = Nothing
-- performer to decide on the best guess to make each turn -- performer to decide on the best guess to make each turn
-- --
feedback :: [Pitch] -> [Pitch] -> (Int, Int, Int) feedback :: [Pitch] -> [Pitch] -> (Int, Int, Int)
feedback target guess = (length correctPitches, correctNotes, correctOctaves) feedback target guess = (pitches, notes, octaves)
where where
-- since pitches are unique in a guess, -- since pitches are unique in a guess,
-- we can use set math to count how many are correct -- we can use set math to count how many are correct
targetSet = S.fromList target targetSet = S.fromList target
guessSet = S.fromList guess guessSet = S.fromList guess
correctPitches = S.intersection targetSet guessSet pitchSet = S.intersection targetSet guessSet
pitches = length pitchSet
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)
-- since notes and octaves are not unique in a guess, -- since notes and octaves are not unique in a guess,
-- we can compare the guess to all possible permutations of the target -- we can compare the guess to all possible permutations of the target
-- and count the pairwise note/octave matches -- and count the pairwise note/octave matches
correctNotes = matches targetNotes guessNotes targetNoPitches = S.toList $ S.difference targetSet pitchSet
correctOctaves = matches targetOctaves guessOctaves 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 -- TODO: comment me
-- --