Let's say that your dictionary words are stored in a collection of some sort - say, a List<String>
. Let's also assume that you know how to build a string that represents the current guessing state (i.e. "-an--an"
from your example).
All you need to do is writing a function like this:
static boolean checkMatch(String candidateWord, String currentGuess) {
return ...;
}
Your function needs to implement this logic:
- If
candidateWord
andcurrentGuess
have different lengths, returnfalse
. Otherwise, - Check each letter of the
candidateWord
against the letter of thecurrentGuess
in the same position - If the letter of the
currentGuess
is a dash'-'
or if it matches the letter ofcandidateWord
in the same position, move on to the next letter - Otherwise, return
false
- Once you reach the end of the word, return
true
.
With this function in hand, you could take the current guess, check it against each dictionary word, and increment the count for each time the checkMatch
returns true
. This would give you the number of potential matches.