package main import ( "bufio" "fmt" "os" ) func main() { game := NewGame() err := game.getWordsFromStdin() if err != nil { fmt.Printf("Error getting Words from stdin: %s\n", err) os.Exit(1) } simulator := NewSimulator(*game) err = simulator.SimulateAllPossibleGames() if err != nil { fmt.Printf("Error simulating all possible games: %s\n", err) os.Exit(1) } //err = game.scoreWordsByCommonLetterLocations() //if err != nil { // fmt.Printf("Error scoring Words: %s\n", err) // os.Exit(1) //} // //_, err = game.printSortedScores() //if err != nil { // fmt.Printf("Error printing sorted scores: %s\n", err) // os.Exit(1) //} for i := 0; i < 3; i++ { guess, score := getGuessAndScoreFromStdin() fmt.Printf("Guess: %s, Score: %d\n", guess, score) game.FilterWords(guess, score) err = game.scoreWordsByCommonLetterLocations() if err != nil { fmt.Printf("Error scoring Words: %s\n", err) os.Exit(1) } _, err = game.printSortedScores() if err != nil { fmt.Printf("Error printing sorted scores: %s\n", err) os.Exit(1) } bestGuess, err := game.getBestGuess() if err != nil { fmt.Printf("Error getting best guess: %s\n", err) os.Exit(1) } fmt.Sprintf("Best Guess: %s", bestGuess) if len(game.Words) == 1 { for word := range game.Words { fmt.Printf("The word is: %s\n", word) os.Exit(0) } } } } func getGuessAndScoreFromStdin() (string, int) { reader := bufio.NewReader(os.Stdin) fmt.Print("Enter Guess: ") guess, _ := reader.ReadString('\n') guess = guess[:len(guess)-1] fmt.Print("Enter Score: ") var score int _, err := fmt.Scanf("%d", &score) if err != nil { fmt.Printf("Error reading score: %s\n", err) os.Exit(1) } return guess, score }