|
@@ -2,7 +2,7 @@ package main
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "os"
|
|
|
+ "slices"
|
|
|
)
|
|
|
|
|
|
type Simulation struct {
|
|
@@ -30,7 +30,13 @@ func (s Simulation) SimulateAllPossibleGames() (string, error) {
|
|
|
totRoundCounts := make(map[string]int)
|
|
|
maxRoundCounts := make(map[string]int)
|
|
|
|
|
|
- for initialWord := range s.Game.Words {
|
|
|
+ var words []string
|
|
|
+ for word := range s.Game.Words {
|
|
|
+ words = append(words, word)
|
|
|
+ }
|
|
|
+ slices.Sort(words)
|
|
|
+
|
|
|
+ for _, initialWord := range words {
|
|
|
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
|
|
|
|
simulatedGame := NewGame()
|
|
@@ -43,6 +49,7 @@ func (s Simulation) SimulateAllPossibleGames() (string, error) {
|
|
|
wordLossCounts[initialWord] = lossCount
|
|
|
totRoundCounts[initialWord] = totalRounds
|
|
|
maxRoundCounts[initialWord] = maxRounds
|
|
|
+ //fmt.Printf("Initial Word: %s Loss Count: %d Max Rounds: %d Total Rounds: %d\n", initialWord, lossCount, maxRounds, totalRounds)
|
|
|
if lossCount < bestGuessLossCount {
|
|
|
bestGuessLossCount = lossCount
|
|
|
bestGuessTotalRounds = totalRounds
|
|
@@ -58,10 +65,7 @@ func (s Simulation) SimulateAllPossibleGames() (string, error) {
|
|
|
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
|
fmt.Print("Simulation completed\n\n")
|
|
|
|
|
|
- err := s.Game.scoreWordsByCommonLetterLocations()
|
|
|
- if err != nil {
|
|
|
- return "", fmt.Errorf("Error scoring Words: %s", err)
|
|
|
- }
|
|
|
+ s.Game.scoreWordsByCommonLetterLocations()
|
|
|
|
|
|
var bestGuess string
|
|
|
for _, word := range s.Game.getSortedScores() {
|
|
@@ -108,6 +112,11 @@ func (s Simulation) SimulateOneInitialWord(game *Game, initialWord string) (loss
|
|
|
|
|
|
func (s Simulation) SimulateOneGame(simulatedGame *Game, initialWord, answer string) (bool, int) {
|
|
|
|
|
|
+ if initialWord == answer {
|
|
|
+ fmt.Printf(" Win in 1 round => %s .. %s\n", initialWord, answer)
|
|
|
+ return true, 1
|
|
|
+ }
|
|
|
+
|
|
|
guess := initialWord
|
|
|
|
|
|
// 10 rounds max just to prevent infinite loops
|
|
@@ -124,31 +133,8 @@ func (s Simulation) SimulateOneGame(simulatedGame *Game, initialWord, answer str
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- //debugPrint(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n")
|
|
|
- //fmt.Printf("Starting Sub Simulation: %+v\n", simulatedGame.Words)
|
|
|
- //simulatedSubGame := NewGame()
|
|
|
- //simulatedSubGame.Words = make(map[string]*Word)
|
|
|
- //for word := range simulatedGame.Words {
|
|
|
- // simulatedSubGame.Words[word] = &Word{Word: word}
|
|
|
- //}
|
|
|
- //subSimulator := NewSimulator(*simulatedSubGame)
|
|
|
- //
|
|
|
- //var err error
|
|
|
- //guess, err = subSimulator.SimulateAllPossibleGames()
|
|
|
- //if err != nil {
|
|
|
- // fmt.Printf("Error simulating all possible games: %s\n", err)
|
|
|
- // os.Exit(1)
|
|
|
- //}
|
|
|
- //fmt.Printf("RESULT OF SUB Guess: %s\n", guess)
|
|
|
-
|
|
|
- var err error
|
|
|
- guess, err = simulatedGame.getBestGuess()
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Error calculating best guess: %s\n", err)
|
|
|
- os.Exit(1)
|
|
|
- }
|
|
|
+ guess = simulatedGame.getBestGuess()
|
|
|
debugPrint("Round %d, guess: %s\n", round, guess)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if guess == answer {
|
|
@@ -161,11 +147,7 @@ func (s Simulation) SimulateOneGame(simulatedGame *Game, initialWord, answer str
|
|
|
simulatedGame.FilterWords(guess, score)
|
|
|
debugPrint("Words remaining after filtering: %+v\n", simulatedGame.Words)
|
|
|
|
|
|
- err := simulatedGame.scoreWordsByCommonLetterLocations()
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Error scoring Words: %s\n", err)
|
|
|
- os.Exit(1)
|
|
|
- }
|
|
|
+ simulatedGame.scoreWordsByCommonLetterLocations()
|
|
|
|
|
|
debugPrint("End round %d, not solved, %d words remaining\n", round, len(simulatedGame.Words))
|
|
|
}
|