feat: generate all possible chords and initialise gameState as all chords

This commit is contained in:
wi11-holdsworth 2025-09-25 11:49:00 +10:00
parent d8dbc1c86c
commit 4618e32d77

View file

@ -16,10 +16,10 @@ import Data.Set qualified as S
type GameState = [[Pitch]] type GameState = [[Pitch]]
data Note = A | B | C | D | E | F | G data Note = A | B | C | D | E | F | G
deriving (Eq, Show, Ord) deriving (Eq, Show, Ord, Enum, Bounded)
data Octave = One | Two | Three data Octave = One | Two | Three
deriving (Eq, Ord) deriving (Eq, Ord, Enum, Bounded)
data Pitch = Pitch data Pitch = Pitch
{ note :: Note, { note :: Note,
@ -79,11 +79,34 @@ feedback target guess = (length correctPitches, correctNotes, correctOctaves)
correctOctaves = length $ S.intersection targetOctaveSet guessOctaveSet correctOctaves = length $ S.intersection targetOctaveSet guessOctaveSet
initialGuess :: ([Pitch], GameState) initialGuess :: ([Pitch], GameState)
initialGuess = ([a1, a2, a3], [[]]) initialGuess = (chord, chords)
where where
a1 = Pitch A One chord : chords = allChords
a2 = Pitch A Two
a3 = Pitch A Three 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 -- implement me
nextGuess :: ([Pitch], GameState) -> (Int, Int, Int) -> ([Pitch], GameState) nextGuess :: ([Pitch], GameState) -> (Int, Int, Int) -> ([Pitch], GameState)