feat: generate all possible chords and initialise gameState as all chords
This commit is contained in:
parent
d8dbc1c86c
commit
4618e32d77
1 changed files with 29 additions and 6 deletions
35
Proj2.hs
35
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue