diff --git a/Proj2.hs b/Proj2.hs index 9eb6454..57d000c 100644 --- a/Proj2.hs +++ b/Proj2.hs @@ -16,10 +16,10 @@ import Data.Set qualified as S type GameState = [[Pitch]] data Note = A | B | C | D | E | F | G - deriving (Eq, Show, Ord) + deriving (Eq, Show, Ord, Enum, Bounded) data Octave = One | Two | Three - deriving (Eq, Ord) + deriving (Eq, Ord, Enum, Bounded) data Pitch = Pitch { note :: Note, @@ -79,11 +79,34 @@ feedback target guess = (length correctPitches, correctNotes, correctOctaves) correctOctaves = length $ S.intersection targetOctaveSet guessOctaveSet initialGuess :: ([Pitch], GameState) -initialGuess = ([a1, a2, a3], [[]]) +initialGuess = (chord, chords) where - a1 = Pitch A One - a2 = Pitch A Two - a3 = Pitch A Three + chord : chords = allChords + +allChords :: [[Pitch]] +allChords = + [ chord + | p1 <- allPitches, + p2 <- allPitches, + p3 <- allPitches, + let chord = [p1, p2, p3], + length (nub chord) == 3, + p1 < p2, + p2 < p3 + ] + +allPitches :: [Pitch] +allPitches = + [ Pitch note octave + | note <- allNotes, + octave <- allOctaves + ] + +allOctaves :: [Octave] +allOctaves = [minBound .. maxBound] + +allNotes :: [Note] +allNotes = [minBound .. maxBound] -- implement me nextGuess :: ([Pitch], GameState) -> (Int, Int, Int) -> ([Pitch], GameState)