-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (63 loc) · 1.68 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"bufio"
"fmt"
"log"
"os"
"github.com/tarndt/wordle/conf"
"github.com/tarndt/wordle/solve"
)
func main() {
dict, letterc, err := solve.LoadDictionary(conf.MustGetArgs())
if err != nil {
log.Fatalf("Could not load dictionary: %s", err)
}
guesser := solve.NewGuesser(dict, letterc)
usr := bufio.NewScanner(os.Stdin)
for {
possibleMatches := guesser.PossibleMatches()
fmt.Printf("%d possible remaining matches of %d letters.\n", possibleMatches, letterc)
recomendation := guesser.Guess()
fmt.Printf("Recommended guess is: %q\n\n", recomendation)
switch possibleMatches {
case 1:
fmt.Println("Our work here is done!")
return
case 0:
fmt.Println("Something went wrong! Check your results for typos, " +
"the dictonary is missing something, or there is a bug :)")
return
}
var guess string
for len(guess) != int(letterc) {
fmt.Printf("Please enter actual guess (%d letters) or enter for %q: ", letterc, recomendation)
if usr.Scan() {
guess = usr.Text()
}
if err := usr.Err(); err != nil {
log.Fatalf("Coult not read user input: %s", err)
}
if solve.ValidResult(guess) {
fmt.Println("You entered a result, not word. Try again.")
guess = ""
continue
}
if guess == "" {
guess = recomendation
}
}
var result string
for len(result) != int(letterc) {
fmt.Printf("Please enter result of guess (%d y|n|p): ", letterc)
if usr.Scan() {
result = usr.Text()
}
if err := usr.Err(); err != nil {
log.Fatalf("Coult not read user input: %s", err)
}
}
if err := guesser.Narrow(guess, result); err != nil {
fmt.Printf("Invalid guess or result: %s. Try again!\n", err)
}
}
}