feat: implement nextGuess with a more complex strategy

possible guesses are now consistent with previously received feedback
This commit is contained in:
wi11-holdsworth 2025-10-02 11:33:13 +10:00
parent bca6ee723d
commit 5969470a70
2 changed files with 12 additions and 16 deletions

View file

@ -54,7 +54,7 @@ import Debug.Trace
-- ==== DATA STRUCTURES =======================================================
-- TODO: INSERT COMMENT HERE
-- contains possible guesses. a possible guess is consistent with all current -- and previous feedback given by the composer
--
type GameState = [[Pitch]]
@ -155,10 +155,19 @@ initialGuess = (chord, chords)
where
chord : chords = allChords
-- TODO: implement me
-- takes in the previous guess, the game state, and the feedback for the
-- previous guess and outputs the next guess and a (reduced in size) game state
--
-- strategy:
-- 1. reduce the size of the search space by removing all guesses inconsistent
-- with the answer received for the previous guess.
-- 2. TODO: mini-max?
--
nextGuess :: ([Pitch], GameState) -> (Int, Int, Int) -> ([Pitch], GameState)
nextGuess (prevGuess, chord : chords) _ = (chord, chords)
nextGuess (prevGuess, chords) answer = (guess, consistentChords)
where
guess : consistentChords = filter consistentWithAnswer chords
consistentWithAnswer chord = answer == feedback prevGuess chord
-- ==== HELPER FUNCTIONS ======================================================