In my algorithm to compare the secret word with the guessed word, I need to manage the duplicated letters. For example,
if the secret word is newly and the guessed word is newer, the output of this should be "GGGWW" (G = green(Correct Place), W = White(The Letter isn't in the secret word)),
but instead my algorithm down below outputs "GGGYW" (Y = Yellow(Letter is in the word but not the right place)).
for (int i = 0; i < 5; i++) {
if (secret.charAt(i) == prop.charAt(i)) {
status[i] = LetterStatus.IN;
} else if (secret.contains(Character.toString(prop.charAt(i)))) {
status[i] = LetterStatus.OK;
} else {
status[i] = LetterStatus.NOTIN;
}
}
return status;
secret = secretword, the array status is an enum of (IN, OK, NOTIN), so the letter and prop status is the guessed word.
Any ideas on how to modify this code to solve my problem