1
0
Fork 0

Fixes to random letter generation:

* If more than 26 letters requested, don't get into an infinite loop.
* Don't give away repeat letters: always give word length + num random
    letters even if that means actually adding more random letters than
    requested due to repeat letters in the word.
master
Daniel Perelman 2 years ago
parent a658310214
commit 0d7fafda5b

@ -60,12 +60,12 @@ class Bagels {
if (iters++ > maxIters) return null;
} while (!regExp.test(word) || !isValidWord(word));
let numLetters = settings.num_random_letters;
let numLetters = Math.min(26, word.length + settings.num_random_letters);
let availableLetters;
let availableLettersValid = false;
do {
availableLetters = new Set(word.split(''));
for (let i = 0; i < numLetters; i++) {
for (let i = availableLetters.size; i < numLetters; i++) {
let newLetter;
do {
newLetter = getRandomLetter();

Loading…
Cancel
Save