I am trying to reverse engineer the following image. So far, the way I would take into account of duplicate letter handling is the following .
I am unsure how I could code this such that the duplicates are not colored incorrectly. For example, in my code output in the first row, the first "N" should not be yellow, but rather dark grey since the other "N" at the center is correctly placed and shaded in green. As there is only 1 N in the secret word (BANAL), then only 1 N must be shaded.
My current approach consists of the following:
public static char[] duplicates(char[] MysteryWordArr, char[] guessArr){
int dup = 0; // adds up dup values
for (int i=0; i<WORD_LENGTH; i++){
if (MysteryWordArr[i] != guessArr[i]){
for(int j=0; j<WORD_LENGTH; j++){
if ((MysteryWordArr[i] == guessArr[j])) {
MysteryWordArr[i] = ' ';
}
else{
continue;
}
}
}
}
return MysteryWordArr;
}
My reasoning is that provided the char at same index of secret and guess are not the same, if the index of secret is equal to any other index of guess, then change that index of secret to a random string (in this empty). This I presumed, would mean that the duplicates would be grey as they cannot compare to their identical value in secret.
What do you think I should do.