Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Letter in word hint not working correctly #5

Closed
Caleb-Barton opened this issue Jan 23, 2022 · 2 comments
Closed

Letter in word hint not working correctly #5

Caleb-Barton opened this issue Jan 23, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Caleb-Barton
Copy link

image

It looks like it highlights every instance of a correct letter. The actual word was shalt, but it highlighted ever S in Sassy. This is not how the original wordle works. I'm assuming that it's supposed to be like wordle, but I don't know for sure.

Anyway, great job on this!

@branwall
Copy link

branwall commented Jan 23, 2022

I believe the logic for this requires two passes through the guess to get the highlighting correct.

First pass: is this letter in the correct spot? If so, green. Is it completely absent from the word? If so, black.
Then, remove all the correct guesses from the answer word so they can't be reused in the comparison.

Second pass: Is this letter in the word at all? (It will necessarily be in the wrong spot.) If so, yellow. Else, black.

Edit: Here's how I solved it using the above logic:

let mutableAnswer = String(answer);
  const output = ["", "", "", "", ""];
  const letters = guess.split("");
  letters.forEach((letter, index) => {
    if (answer[index] === letter) {
      mutableAnswer = mutableAnswer.replace(letter, 0); //this ensures the letter won't be "in" the answer 
//for purposes of marking it yellow when the user guessed it in the correct position already, 
//without reordering the remaining letters in the answer.
      output[index] = green;
    } else if (answer.indexOf(letter) === -1) {
      output[index] = black;
    }
  });
  letters.forEach((letter, index) => {
    if (!output[index] && mutableAnswer.indexOf(letter) > -1) {
      output[index] = yellow;
      mutableAnswer = mutableAnswer.replace(letter, 0);
    } else if (!output[index]) {
      output[index] = black;
    }
  });
  return output;

@MikhaD MikhaD changed the title Too much yellow highlighting Letter in word hint not working correctly Jan 23, 2022
@MikhaD
Copy link
Owner

MikhaD commented Jan 23, 2022

The actual Wordle doesn't mark a letter as yellow unless there is at least one more of the guessed letter in the actual word in an unknown location. I just played and got the word "MANIA" as the answer. But when I guessed "INDIA," I got 🟨🟨⬛️🟩🟩 instead of ⬛️🟨⬛️🟩🟩. You can verify how the actual Wordle works by guessing primp for today's word. You'll see that the first P is black, not yellow, even though a second P exists in the word.

~ Courtesy of flyguy33443322 on reddit.

@MikhaD MikhaD self-assigned this Jan 23, 2022
@MikhaD MikhaD added the bug Something isn't working label Jan 23, 2022
@MikhaD MikhaD closed this as completed in 2cc61b9 Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants