I am making a game, in which a user types or to be precise clicks on a 4x4 board to create a meaningful word. The issue is my random distribution of letters on the board leads to prevailing of consonants, which makes it hard to find words. Like on the picture (only 3 vowels). So my question, is there any formula or algorithm to distribute consonants and vowels nearly equally maybe 10 (consonants) to 6 (vowels)? Or can you suggest a solution.
The way I display letters randomly is the following:
const letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z'];
var searched_word = '';
var tr = '';
var wordsBank = [];
var wordsCount = 0;
var boxes = document.querySelectorAll('.square');
//console.log(boxes);
boxes.forEach(function(box) {
box.addEventListener('click', function(e) {
e.preventDefault();
searched_word += this.innerHTML;
document.querySelector('.input').value = searched_word;
});
console.log(searched_word);
return searched_word;
});
function randomLetters(boxes) {
for (var i = 0; i < boxes.length; i++) {
let box = boxes[i];
let randomLetterNumber = Math.floor(Math.random() * letters.length);
box.innerHTML = letters[randomLetterNumber].toLocaleUpperCase();
//console.log(box);
//console.log(randomLetterNumber);
}
}
Aucun commentaire:
Enregistrer un commentaire