|
@@ -23,9 +23,11 @@ func NewSimulator(g Game) *Simulation {
|
|
func (s Simulation) SimulateAllPossibleGames() (string, error) {
|
|
func (s Simulation) SimulateAllPossibleGames() (string, error) {
|
|
|
|
|
|
bestGuessLossCount := 99
|
|
bestGuessLossCount := 99
|
|
|
|
+ bestGuessMaxRounds := 99
|
|
bestGuessTotalRounds := 99
|
|
bestGuessTotalRounds := 99
|
|
|
|
|
|
wordLossCounts := make(map[string]int)
|
|
wordLossCounts := make(map[string]int)
|
|
|
|
+ totRoundCounts := make(map[string]int)
|
|
maxRoundCounts := make(map[string]int)
|
|
maxRoundCounts := make(map[string]int)
|
|
|
|
|
|
for initialWord := range s.Game.Words {
|
|
for initialWord := range s.Game.Words {
|
|
@@ -37,18 +39,24 @@ func (s Simulation) SimulateAllPossibleGames() (string, error) {
|
|
simulatedGame.Words[word] = &Word{Word: word}
|
|
simulatedGame.Words[word] = &Word{Word: word}
|
|
}
|
|
}
|
|
|
|
|
|
- lossCount, maxRounds, _ := s.SimulateOneInitialWord(simulatedGame, initialWord)
|
|
|
|
|
|
+ lossCount, maxRounds, totalRounds := s.SimulateOneInitialWord(simulatedGame, initialWord)
|
|
wordLossCounts[initialWord] = lossCount
|
|
wordLossCounts[initialWord] = lossCount
|
|
|
|
+ totRoundCounts[initialWord] = totalRounds
|
|
maxRoundCounts[initialWord] = maxRounds
|
|
maxRoundCounts[initialWord] = maxRounds
|
|
if lossCount < bestGuessLossCount {
|
|
if lossCount < bestGuessLossCount {
|
|
bestGuessLossCount = lossCount
|
|
bestGuessLossCount = lossCount
|
|
- bestGuessTotalRounds = maxRounds
|
|
|
|
- } else if lossCount == bestGuessLossCount && maxRounds < bestGuessTotalRounds {
|
|
|
|
- bestGuessTotalRounds = maxRounds
|
|
|
|
|
|
+ bestGuessTotalRounds = totalRounds
|
|
|
|
+ bestGuessMaxRounds = maxRounds
|
|
|
|
+ } else if lossCount == bestGuessLossCount && maxRounds < bestGuessMaxRounds {
|
|
|
|
+ bestGuessTotalRounds = totalRounds
|
|
|
|
+ bestGuessMaxRounds = maxRounds
|
|
|
|
+ } else if lossCount == bestGuessLossCount && maxRounds == bestGuessMaxRounds && totalRounds < bestGuessTotalRounds {
|
|
|
|
+ bestGuessTotalRounds = totalRounds
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
|
|
+ fmt.Print("Simulation completed\n\n")
|
|
|
|
|
|
err := s.Game.scoreWordsByCommonLetterLocations()
|
|
err := s.Game.scoreWordsByCommonLetterLocations()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -57,8 +65,8 @@ func (s Simulation) SimulateAllPossibleGames() (string, error) {
|
|
|
|
|
|
var bestGuess string
|
|
var bestGuess string
|
|
for _, word := range s.Game.getSortedScores() {
|
|
for _, word := range s.Game.getSortedScores() {
|
|
- if wordLossCounts[word] == bestGuessLossCount && maxRoundCounts[word] == bestGuessTotalRounds {
|
|
|
|
- fmt.Printf("\nBest Guess: %s Failed Branches: %d Max Rounds: %d\n\n", word, bestGuessLossCount, maxRoundCounts[word])
|
|
|
|
|
|
+ if wordLossCounts[word] == bestGuessLossCount && totRoundCounts[word] == bestGuessTotalRounds && maxRoundCounts[word] == bestGuessMaxRounds {
|
|
|
|
+ fmt.Printf("Best Guess: %s Failed Branches: %d Total Rounds: %d Max Rounds: %d\n\n", word, bestGuessLossCount, bestGuessTotalRounds, bestGuessMaxRounds)
|
|
bestGuess = word
|
|
bestGuess = word
|
|
break
|
|
break
|
|
}
|
|
}
|
|
@@ -73,7 +81,7 @@ func (s Simulation) SimulateOneInitialWord(game *Game, initialWord string) (loss
|
|
|
|
|
|
for answer := range s.Game.Words {
|
|
for answer := range s.Game.Words {
|
|
|
|
|
|
- debugPrint(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
|
|
|
|
+ debugPrint(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n")
|
|
|
|
|
|
debugPrint("Target Word: %s\n", answer)
|
|
debugPrint("Target Word: %s\n", answer)
|
|
|
|
|
|
@@ -106,11 +114,18 @@ func (s Simulation) SimulateOneGame(simulatedGame *Game, initialWord, answer str
|
|
var round int
|
|
var round int
|
|
for round = 1; round <= 10; round++ {
|
|
for round = 1; round <= 10; round++ {
|
|
|
|
|
|
|
|
+ if len(simulatedGame.Words) == 1 {
|
|
|
|
+ debugPrint("Only one guess remaining after filtering: %s\n", guess)
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
if round == 1 {
|
|
if round == 1 {
|
|
debugPrint("First guess, initial Word: %s\n", initialWord)
|
|
debugPrint("First guess, initial Word: %s\n", initialWord)
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
+ //debugPrint(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n")
|
|
|
|
+ //fmt.Printf("Starting Sub Simulation: %+v\n", simulatedGame.Words)
|
|
//simulatedSubGame := NewGame()
|
|
//simulatedSubGame := NewGame()
|
|
//simulatedSubGame.Words = make(map[string]*Word)
|
|
//simulatedSubGame.Words = make(map[string]*Word)
|
|
//for word := range simulatedGame.Words {
|
|
//for word := range simulatedGame.Words {
|
|
@@ -124,6 +139,7 @@ func (s Simulation) SimulateOneGame(simulatedGame *Game, initialWord, answer str
|
|
// fmt.Printf("Error simulating all possible games: %s\n", err)
|
|
// fmt.Printf("Error simulating all possible games: %s\n", err)
|
|
// os.Exit(1)
|
|
// os.Exit(1)
|
|
//}
|
|
//}
|
|
|
|
+ //fmt.Printf("RESULT OF SUB Guess: %s\n", guess)
|
|
|
|
|
|
var err error
|
|
var err error
|
|
guess, err = simulatedGame.getBestGuess()
|
|
guess, err = simulatedGame.getBestGuess()
|
|
@@ -135,28 +151,15 @@ func (s Simulation) SimulateOneGame(simulatedGame *Game, initialWord, answer str
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- score := s.getScore(guess, answer)
|
|
|
|
- debugPrint("guess '%s' matches %d locations in answer '%s'\n", guess, score, answer)
|
|
|
|
-
|
|
|
|
- simulatedGame.FilterWords(guess, score)
|
|
|
|
- debugPrint("Words remaining after filtering: %+v\n", simulatedGame.Words)
|
|
|
|
-
|
|
|
|
if guess == answer {
|
|
if guess == answer {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
|
|
|
|
- if len(simulatedGame.Words) == 1 {
|
|
|
|
- debugPrint("The word is: %s\n", guess)
|
|
|
|
- for word := range simulatedGame.Words {
|
|
|
|
-
|
|
|
|
- if word != answer {
|
|
|
|
- fmt.Printf("Incorrectly guessed word: %s => This should never happen!\n", word)
|
|
|
|
- os.Exit(1)
|
|
|
|
- }
|
|
|
|
|
|
+ score := s.getScore(guess, answer)
|
|
|
|
+ debugPrint("guess '%s' matches %d locations in answer '%s'\n", guess, score, answer)
|
|
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ simulatedGame.FilterWords(guess, score)
|
|
|
|
+ debugPrint("Words remaining after filtering: %+v\n", simulatedGame.Words)
|
|
|
|
|
|
err := simulatedGame.scoreWordsByCommonLetterLocations()
|
|
err := simulatedGame.scoreWordsByCommonLetterLocations()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -168,11 +171,11 @@ func (s Simulation) SimulateOneGame(simulatedGame *Game, initialWord, answer str
|
|
}
|
|
}
|
|
|
|
|
|
if round > 4 {
|
|
if round > 4 {
|
|
- fmt.Printf("Loss: Matched in %d rounds => Initial Word: %s Target Word: %s\n", round, initialWord, answer)
|
|
|
|
|
|
+ fmt.Printf(" Loss in %d rounds => %s .. %s\n", round, initialWord, answer)
|
|
return false, round
|
|
return false, round
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Printf("Win: Matched in %d rounds => Initial Word: %s Target Word: %s\n", round, initialWord, answer)
|
|
|
|
|
|
+ fmt.Printf(" Win in %d rounds => %s .. %s\n", round, initialWord, answer)
|
|
return true, round
|
|
return true, round
|
|
}
|
|
}
|
|
|
|
|