Skip to content

Commit

Permalink
Play all permutations and report how well the strategy performs.
Browse files Browse the repository at this point in the history
  • Loading branch information
archy-bold committed Jan 5, 2022
1 parent baf73d7 commit 5561bce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ func main() {
wordPtr := flag.String("word", "", "The game's answer")
playPtr := flag.Bool("play", false, "Whether to play the game")
autoPtr := flag.Bool("auto", false, "Play the game automatically")
allPtr := flag.Bool("all", false, "Play all permutations")
flag.Parse()

auto := *autoPtr

// Read the valid words
fmt.Println("Reading words...")
fmt.Print("Reading words... ")
err := readValidWords()
fmt.Printf("Found %d\n", len(validWords))
fmt.Printf("found %d\n", len(validWords))
check(err)

reader := bufio.NewReader(os.Stdin)
Expand All @@ -45,6 +46,40 @@ func main() {
strat = strategy.NewCharFrequencyStrategy(NUM_LETTERS, letters, &validWords)
}

// Play out all permutations
if *allPtr {
sumTries := 0
numSuccesses := 0
for _, answer := range validWords {
strat = strategy.NewCharFrequencyStrategy(NUM_LETTERS, letters, &validWords)
g := game.CreateGame(answer, NUM_ATTEMPTS)

for {
word := strat.GetNextMove()
success, _ := g.Play(word)
strat.SetMoveOutcome(g.GetLastPlay())

if success {
score, of := g.GetScore()
fmt.Printf("%s in %d/%d\n", answer, score, of)
numSuccesses++
sumTries += score

break
} else if g.HasEnded() {
fmt.Printf("%s failed\n", answer)
break
}

}
}

fmt.Printf("Completed %d/%d\n", numSuccesses, len(validWords))
fmt.Printf("On average %f\n", float64(sumTries)/float64(numSuccesses))

return
}

if *playPtr {
// If no answer given in the word flag, choose
answer := *wordPtr
Expand Down
Binary file modified wordle
Binary file not shown.

0 comments on commit 5561bce

Please sign in to comment.