fallout.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "os"
  6. )
  7. func main() {
  8. game := NewGame()
  9. err := game.getWordsFromStdin()
  10. if err != nil {
  11. fmt.Printf("Error getting Words from stdin: %s\n", err)
  12. os.Exit(1)
  13. }
  14. simulator := NewSimulator(*game)
  15. err = simulator.SimulateAllPossibleGames()
  16. if err != nil {
  17. fmt.Printf("Error simulating all possible games: %s\n", err)
  18. os.Exit(1)
  19. }
  20. //err = game.scoreWordsByCommonLetterLocations()
  21. //if err != nil {
  22. // fmt.Printf("Error scoring Words: %s\n", err)
  23. // os.Exit(1)
  24. //}
  25. //
  26. //_, err = game.printSortedScores()
  27. //if err != nil {
  28. // fmt.Printf("Error printing sorted scores: %s\n", err)
  29. // os.Exit(1)
  30. //}
  31. for i := 0; i < 3; i++ {
  32. guess, score := getGuessAndScoreFromStdin()
  33. fmt.Printf("Guess: %s, Score: %d\n", guess, score)
  34. game.FilterWords(guess, score)
  35. err = game.scoreWordsByCommonLetterLocations()
  36. if err != nil {
  37. fmt.Printf("Error scoring Words: %s\n", err)
  38. os.Exit(1)
  39. }
  40. _, err = game.printSortedScores()
  41. if err != nil {
  42. fmt.Printf("Error printing sorted scores: %s\n", err)
  43. os.Exit(1)
  44. }
  45. bestGuess, err := game.getBestGuess()
  46. if err != nil {
  47. fmt.Printf("Error getting best guess: %s\n", err)
  48. os.Exit(1)
  49. }
  50. fmt.Sprintf("Best Guess: %s", bestGuess)
  51. if len(game.Words) == 1 {
  52. for word := range game.Words {
  53. fmt.Printf("The word is: %s\n", word)
  54. os.Exit(0)
  55. }
  56. }
  57. }
  58. }
  59. func getGuessAndScoreFromStdin() (string, int) {
  60. reader := bufio.NewReader(os.Stdin)
  61. fmt.Print("Enter Guess: ")
  62. guess, _ := reader.ReadString('\n')
  63. guess = guess[:len(guess)-1]
  64. fmt.Print("Enter Score: ")
  65. var score int
  66. _, err := fmt.Scanf("%d", &score)
  67. if err != nil {
  68. fmt.Printf("Error reading score: %s\n", err)
  69. os.Exit(1)
  70. }
  71. return guess, score
  72. }