diff --git a/website/game.js b/website/game.js index 3534bb8..d2193d2 100644 --- a/website/game.js +++ b/website/game.js @@ -113,7 +113,8 @@ function getWDL(data) { // Since we don't save the individual guesses per round. // We have to compute them ourselves. - let guesses = getGuessesPerRound(data); + let guesses = getGuessesPerRound(data.hints, data.revealed, data.secret); + console.log(`Guesses per round: ${guesses}`); // We check whether the guesses of the last round contain a mistake. for (let word of guesses[guesses.length-1]) { @@ -251,6 +252,7 @@ async function main(date, datas) { function handleCardClick(word) { console.log("Card clicked:", word); if (data.roundOver) { + // Shouldn't be possible to get here console.log("Round over, please start next round."); return; } @@ -262,6 +264,7 @@ async function main(date, datas) { return; } + // Get the last hint that the user saw before clicking const {clue, n} = data.hints[data.hints.length-1]; gtag('event', 'card_click', { @@ -291,6 +294,7 @@ async function main(date, datas) { data.roundOver = true; } + console.log(`Is game over? ${isGameOver(data)} ${getWDL(data)}`); if (isGameOver(data)) { onGameOver(); } @@ -708,27 +712,32 @@ function makeHint(matrix, words, stopwords, board, secret, aggressiveness, shift return combinedBest; } -function getGuessesPerRound(data) { +function getGuessesPerRound(hints, revealed, secret) { let j = 0; const result = []; - for (const hint of data.hints) { + for (const hint of hints) { const guesses = []; while ( - j !== data.revealed.length // Not through all actions yet. - && data.secret.includes(data.revealed[j]) // No mistake yet. - && guesses.length != hint.n // Haven't finished by success. + j !== revealed.length // Not through all actions yet. + && secret.includes(revealed[j]) // No mistake yet. + && guesses.length != hint.n // Haven't finished by success. ) { - guesses.push(data.revealed[j]); + guesses.push(revealed[j]); + j++; + } + // Maybe add a mistake + if (j !== revealed.length && guesses.length != hint.n) { + guesses.push(revealed[j]); j++; } result.push(guesses); } // If we just started a new round - if (result.length == data.hints.length-1) { + if (result.length == hints.length-1) { result.push([]); } - if (result.length != data.hints.length) { - console.log(`Bad length ${result.length}, ${data.hints.length}.`); + if (result.length != hints.length) { + console.log(`Bad length ${result.length}, ${hints.length}.`); } return result; @@ -737,28 +746,13 @@ function getGuessesPerRound(data) { function compileLog(hints, revealed, secret) { let shareString = ""; let s = "
Round ${i + 1} Clue: ${hint.clue.toUpperCase()} ${hint.n}
`; s += "