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 ======================================================

View file

@ -1,18 +1,5 @@
# Spec
## Tips to improve `nextGuess`
A better approach would be to only make guesses that are consistent with the
answers you have received for previous guesses. You can do this by computing
the list of possible targets, and removing elements that are inconsistent with
any answers you have received to previous guesses. A possible target is
inconsistent with an answer you have received for a previous guess if the
answer you would receive for that guess and that (possible) target is different
from the answer you actually received for that guess.
You can use your GameState type to store your previous guesses and the
corresponding answers. Or, more efficient and just as easy, store the list of
remaining possible targets in your GameState, and pare it down each time you
receive feedback for a guess.
The best results can be had by carefully choosing each guess so that it is most
likely to leave a small remaining list of possible targets. You can do this by
computing for each remaining possible target the maximum number of possible