docs: comment data structures
This commit is contained in:
parent
0b87d62ba0
commit
96b7053c5d
1 changed files with 30 additions and 1 deletions
31
Proj2.hs
31
Proj2.hs
|
|
@ -54,8 +54,12 @@ import Debug.Trace
|
||||||
|
|
||||||
-- ==== DATA STRUCTURES =======================================================
|
-- ==== DATA STRUCTURES =======================================================
|
||||||
|
|
||||||
|
-- TODO: INSERT COMMENT HERE
|
||||||
|
--
|
||||||
type GameState = [[Pitch]]
|
type GameState = [[Pitch]]
|
||||||
|
|
||||||
|
-- represents a pitch, which is made of a note and a chord
|
||||||
|
--
|
||||||
data Pitch = Pitch
|
data Pitch = Pitch
|
||||||
{ note :: Note,
|
{ note :: Note,
|
||||||
octave :: Octave
|
octave :: Octave
|
||||||
|
|
@ -65,9 +69,13 @@ data Pitch = Pitch
|
||||||
instance Show Pitch where
|
instance Show Pitch where
|
||||||
show (Pitch note octave) = show note ++ show octave
|
show (Pitch note octave) = show note ++ show octave
|
||||||
|
|
||||||
|
-- represents a standard musical note
|
||||||
|
--
|
||||||
data Note = A | B | C | D | E | F | G
|
data Note = A | B | C | D | E | F | G
|
||||||
deriving (Bounded, Enum, Eq, Ord, Show)
|
deriving (Bounded, Enum, Eq, Ord, Show)
|
||||||
|
|
||||||
|
-- represents an octave of 1, 2 or 3
|
||||||
|
--
|
||||||
data Octave = One | Two | Three
|
data Octave = One | Two | Three
|
||||||
deriving (Bounded, Enum, Eq, Ord)
|
deriving (Bounded, Enum, Eq, Ord)
|
||||||
|
|
||||||
|
|
@ -78,6 +86,12 @@ instance Show Octave where
|
||||||
|
|
||||||
-- ==== REQUIRED FUNCTIONS ====================================================
|
-- ==== REQUIRED FUNCTIONS ====================================================
|
||||||
|
|
||||||
|
-- takes in a pitch-like string as input and outputs a pitch if conversion was
|
||||||
|
-- successful, or nothing if it failed. a "pitch-like" string can be something
|
||||||
|
-- like "A1" or "B2"
|
||||||
|
--
|
||||||
|
-- used in the testing framework as a utility function
|
||||||
|
--
|
||||||
toPitch :: String -> Maybe Pitch
|
toPitch :: String -> Maybe Pitch
|
||||||
toPitch [note, octave] = Pitch <$> charToNote note <*> charToOctave octave
|
toPitch [note, octave] = Pitch <$> charToNote note <*> charToOctave octave
|
||||||
where
|
where
|
||||||
|
|
@ -103,6 +117,18 @@ toPitch [note, octave] = Pitch <$> charToNote note <*> charToOctave octave
|
||||||
]
|
]
|
||||||
toPitch _ = Nothing
|
toPitch _ = Nothing
|
||||||
|
|
||||||
|
-- takes a target chord (usually created by the composer) and a guess chord,
|
||||||
|
-- and outputs an integer 3-tuple of feedback, where each element is the
|
||||||
|
-- number of correct items in the guess:
|
||||||
|
--
|
||||||
|
-- (pitches, notes, octaves)
|
||||||
|
--
|
||||||
|
-- as per the explanation at the top of this file, notes and octaves are not
|
||||||
|
-- double-counted
|
||||||
|
--
|
||||||
|
-- used in the testing framework as a utility function, and also by the
|
||||||
|
-- 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 = (length correctPitches, correctNotes, correctOctaves)
|
||||||
where
|
where
|
||||||
|
|
@ -125,12 +151,15 @@ feedback target guess = (length correctPitches, correctNotes, correctOctaves)
|
||||||
correctNotes = matches targetNotes guessNotes
|
correctNotes = matches targetNotes guessNotes
|
||||||
correctOctaves = matches targetOctaves guessOctaves
|
correctOctaves = matches targetOctaves guessOctaves
|
||||||
|
|
||||||
|
-- TODO: comment me
|
||||||
|
--
|
||||||
initialGuess :: ([Pitch], GameState)
|
initialGuess :: ([Pitch], GameState)
|
||||||
initialGuess = (chord, chords)
|
initialGuess = (chord, chords)
|
||||||
where
|
where
|
||||||
chord : chords = allChords
|
chord : chords = allChords
|
||||||
|
|
||||||
-- implement me
|
-- TODO: implement me
|
||||||
|
--
|
||||||
nextGuess :: ([Pitch], GameState) -> (Int, Int, Int) -> ([Pitch], GameState)
|
nextGuess :: ([Pitch], GameState) -> (Int, Int, Int) -> ([Pitch], GameState)
|
||||||
nextGuess (prevGuess, chord : chords) _ = (chord, chords)
|
nextGuess (prevGuess, chord : chords) _ = (chord, chords)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue