Browse Source

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 4 months ago
parent
commit
0d7fafda5b
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      www/bagels/bagels.js

+ 2
- 2
www/bagels/bagels.js View File

@@ -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