12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 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)
- }
- 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)
- }
- 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
- }
|