docs: comment helper functions
This commit is contained in:
parent
1d86b09e0f
commit
bca6ee723d
1 changed files with 13 additions and 0 deletions
13
Proj2.hs
13
Proj2.hs
|
|
@ -162,12 +162,25 @@ nextGuess (prevGuess, chord : chords) _ = (chord, chords)
|
||||||
|
|
||||||
-- ==== HELPER FUNCTIONS ======================================================
|
-- ==== 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 :: (Eq a, Show a) => [a] -> [a] -> Int
|
||||||
matches xs ys = maximum permutationMatches
|
matches xs ys = maximum permutationMatches
|
||||||
where
|
where
|
||||||
permutationMatches = map (pairwiseMatches xs) (permutations ys)
|
permutationMatches = map (pairwiseMatches xs) (permutations ys)
|
||||||
pairwiseMatches xs ys = length $ filter (uncurry (==)) $ zip xs 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 :: [[Pitch]]
|
||||||
allChords =
|
allChords =
|
||||||
[ chord
|
[ chord
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue