feat: implement feedback
This commit is contained in:
parent
00e2dae6c1
commit
d3aa836a8f
1 changed files with 19 additions and 1 deletions
20
Proj2.hs
20
Proj2.hs
|
|
@ -11,6 +11,9 @@ module Proj2
|
|||
where
|
||||
|
||||
type GameState = ()
|
||||
import Data.List
|
||||
import Data.Set qualified as S
|
||||
|
||||
|
||||
data Note = A | B | C | D | E | F | G
|
||||
deriving (Eq, Show, Ord)
|
||||
|
|
@ -58,7 +61,22 @@ toPitch [note, octave] = Pitch <$> charToNote note <*> charToOctave octave
|
|||
toPitch _ = Nothing
|
||||
|
||||
feedback :: [Pitch] -> [Pitch] -> (Int, Int, Int)
|
||||
feedback _ _ = (0, 0, 0)
|
||||
feedback target guess = (length correctPitches, correctNotes, correctOctaves)
|
||||
where
|
||||
targetSet = S.fromList target
|
||||
guessSet = S.fromList guess
|
||||
|
||||
correctPitches = S.intersection targetSet guessSet
|
||||
newTarget = S.difference targetSet correctPitches
|
||||
newGuess = S.difference guessSet correctPitches
|
||||
|
||||
targetNoteSet = S.map note newTarget
|
||||
guessNoteSet = S.map note newGuess
|
||||
targetOctaveSet = S.map octave newTarget
|
||||
guessOctaveSet = S.map octave newGuess
|
||||
|
||||
correctNotes = length $ S.intersection targetNoteSet guessNoteSet
|
||||
correctOctaves = length $ S.intersection targetOctaveSet guessOctaveSet
|
||||
|
||||
-- implement me
|
||||
initialGuess :: ([Pitch], GameState)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue