From d3aa836a8fb8be599e28c54fd029cb90f1b62631 Mon Sep 17 00:00:00 2001 From: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Wed, 24 Sep 2025 14:54:13 +1000 Subject: [PATCH] feat: implement feedback --- Proj2.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Proj2.hs b/Proj2.hs index a9d30b6..6a23ce6 100644 --- a/Proj2.hs +++ b/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)