Skip to content

Commit

Permalink
Merge pull request #7 from pemcne/wordle-guesses
Browse files Browse the repository at this point in the history
Correctly display guesses if incorrect
  • Loading branch information
pemcne committed Feb 14, 2024
2 parents fdad38d + c79bb2c commit 28e7de1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions wordle-solve.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ func scoreGuess(guess, solution string, state *WordState) bool {
return false
}

func printGame(state *WordState, game int) string {
out := fmt.Sprintf("Wordle %d %d/6*\n", game, len(state.history[0]))
func printGame(state *WordState, game int, correct bool) string {
total := "X"
if correct {
total = fmt.Sprintf("%d", len(state.history[0]))
}
out := fmt.Sprintf("Wordle %d %s/6*\n", game, total)
for guess := len(state.history[0]) - 1; guess >= 0; guess-- {
line := ""
for letter := 0; letter < 5; letter++ {
Expand Down Expand Up @@ -233,15 +237,16 @@ func SolveWordle(msg joe.Message) error {
state.history[i] = make([]SolveLetterState, 0)
}
guesses := []string{}
correct := false
for i := 0; i < 6; i++ {
guess := nextGuess(&state)
guesses = append(guesses, guess)
correct := scoreGuess(guess, solution.Solution, &state)
correct = scoreGuess(guess, solution.Solution, &state)
if correct {
break
}
}
msg.Respond(printGame(&state, solution.GameId))
msg.Respond(printGame(&state, solution.GameId, correct))
outGuesses, err := json.Marshal(guesses)
if err != nil {
return err
Expand Down

0 comments on commit 28e7de1

Please sign in to comment.