Good evening to all,
I've been trying for several days to create a Discord bot in Javascript that will launch a famous game: Motus.
The goal of the game is to find a word between 7 and 10 characters. To do this, the player submits several words of the same size to see if there are letters in it.
There are three rules: the letters can be misplaced but present in the word, the letters can be absent and the letters can be well placed.
Through the submissions, it is possible to determine which letters are present and which are not.
I have a problem in my case where there are several occurrences in the submissions or the word to be found.
The duplicate letter should be considered false, because if in the word to be found there is only one "t" for example, the misplaced letter or one of the misplaced letters should be removed.
Here is my code where I try to manage the case where the user sends several letters or less in relation to the word to be found.
Currently, he can find the well placed one, but does not cross out the extra one, he only considers them badly placed.
Any help is appreciated.
if ((occurenceUser != occurenceWord) && occurenceWord != 0) {
array = allIndexOf(userWord, userWord.charAt(i))
secondarray = allIndexOf(word, userWord.charAt(i))
for (var j = 0; j < array.length; j++)
for (var k = 0; k < secondarray.length; k++)
if (array[j] == secondarray[k])
goodOccurence.push(array[j])
for (var j = 0; j < goodOccurence.length; j++) {
if (goodOccurence[j] == i) {
result = result + "**" + userWord.charAt(i) + "** "
break
} else if (goodOccurence[j] != i) {
result = result + userWord.charAt(i) + " "
break
} else {
result = result + "~~" + userWord.charAt(i) + "~~ "
break
}
}
}
question from:
https://stackoverflow.com/questions/65925518/how-to-check-occurence-time-in-javascript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…