diff --git a/Proj2.hs b/Proj2.hs index ff9f91e..6d4c01c 100644 --- a/Proj2.hs +++ b/Proj2.hs @@ -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 ====================================================== diff --git a/README.md b/README.md index 3809ffd..1490f0c 100644 --- a/README.md +++ b/README.md @@ -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