docs: comment helper functions

This commit is contained in:
wi11-holdsworth 2025-10-01 14:34:35 +10:00
parent 1d86b09e0f
commit bca6ee723d

View file

@ -162,12 +162,25 @@ nextGuess (prevGuess, chord : chords) _ = (chord, chords)
-- ==== HELPER FUNCTIONS ======================================================
-- given lists xs and ys, calculates the maximum number of pairwise matches
-- between xs and all permutations of ys
--
-- used in the feedback function to calculate the number of correct notes
-- and/or octaves
--
matches :: (Eq a, Show a) => [a] -> [a] -> Int
matches xs ys = maximum permutationMatches
where
permutationMatches = map (pairwiseMatches xs) (permutations ys)
pairwiseMatches xs ys = length $ filter (uncurry (==)) $ zip xs ys
-- outputs a list of all possible chords, where a chord is a list of unique
-- pitches. this function happens to generate chords such that the pitches are
-- in alphabetical order, but this is only to ensure that there are no
-- duplicate pitches
--
-- used in initialGuess as the game state (represents all possible targets)
--
allChords :: [[Pitch]]
allChords =
[ chord