fix matrix algo
This commit is contained in:
parent
48646c5740
commit
aaeb0d7752
29
game.js
29
game.js
|
@ -60,17 +60,34 @@ class Game {
|
||||||
result.push(3)
|
result.push(3)
|
||||||
} else {
|
} else {
|
||||||
if (this.expectedWord.indexOf(triedLetter) > -1) {
|
if (this.expectedWord.indexOf(triedLetter) > -1) {
|
||||||
const numberOfTriedLetterInExpectedWord = this.expectedWord.split(triedLetter).length - 1
|
let totalOk = 0
|
||||||
const cuttedTriedWord = this.triedWords[u].substr(0, x + 1)
|
let totalToTry = 0
|
||||||
const numberOfTriedLetterInCuttedWord = cuttedTriedWord.split(triedLetter).length - 1
|
|
||||||
|
|
||||||
if (numberOfTriedLetterInCuttedWord > numberOfTriedLetterInExpectedWord) {
|
for (let i = 0; i < this.expectedWord.length; i++) {
|
||||||
|
if (this.expectedWord.charAt(i) === triedLetter) {
|
||||||
|
totalToTry++
|
||||||
|
|
||||||
|
if (this.expectedWord.charAt(i) === this.triedWords[u].charAt(i)) {
|
||||||
|
totalOk++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalToTry === totalOk) {
|
||||||
result.push(1)
|
result.push(1)
|
||||||
} else {
|
} else {
|
||||||
result.push(2)
|
const numberOfTriedLetterInExpectedWord = this.expectedWord.split(triedLetter).length - 1
|
||||||
|
const cuttedTriedWord = this.triedWords[u].substr(0, x + 1)
|
||||||
|
const numberOfTriedLetterInCuttedWord = cuttedTriedWord.split(triedLetter).length - 1
|
||||||
|
|
||||||
|
if (numberOfTriedLetterInCuttedWord > numberOfTriedLetterInExpectedWord) {
|
||||||
|
result.push(1)
|
||||||
|
} else {
|
||||||
|
result.push(2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.push(1)
|
result.push(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue