no frequent repetitions, choices are a bit less obviuos

This commit is contained in:
Трошин Антон Валерьевич
2026-07-12 10:18:32 +03:00
parent 45cd0ee838
commit 983190d146
4 changed files with 28 additions and 12 deletions
+9 -2
View File
@@ -335,6 +335,7 @@ function startGame() {
game.currentRound = 0;
game.correctCount = 0;
game.mistakes = [];
game.lastAnswer = null;
document.getElementById('score-correct').textContent = '0';
document.getElementById('score-total').textContent = '0';
@@ -352,7 +353,12 @@ function nextRound() {
game.currentRound++;
game.answered = false;
game.correctAnswer = randInt(game.range.min, game.range.max);
let num;
do {
num = randInt(game.range.min, game.range.max);
} while (num === game.lastAnswer && game.range.min !== game.range.max);
game.correctAnswer = num;
game.lastAnswer = num;
document.getElementById('score-total').textContent = game.currentRound;
document.getElementById('score-correct').textContent = game.correctCount;
@@ -382,7 +388,8 @@ function renderChoices() {
choiceArea.classList.remove('hidden');
numpadArea.classList.add('hidden');
const choices = generateChoices(game.correctAnswer, [game.range.min, game.range.max], 3);
const nonpos = ['roman', 'greek', 'slavonic', 'hebrew'];
const choices = generateChoices(game.correctAnswer, [game.range.min, game.range.max], 3, nonpos.includes(game.system));
choices.forEach((val, i) => {
const btn = document.getElementById('choice-' + i);
btn.textContent = val;
+3 -3
View File
@@ -10,7 +10,7 @@
<link rel="manifest" href="manifest.json">
<link rel="icon" type="image/svg+xml" href="icon.svg">
<link rel="apple-touch-icon" href="icon-192.png">
<link rel="stylesheet" href="styles.css?v=37">
<link rel="stylesheet" href="styles.css?v=38">
</head>
<body>
<div id="app">
@@ -155,10 +155,10 @@
</div>
<script type="module" src="app.js?v=37"></script>
<script type="module" src="app.js?v=38"></script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js?v=37').catch(() => {});
navigator.serviceWorker.register('/sw.js?v=38').catch(() => {});
}
</script>
</body>
+15 -6
View File
@@ -191,17 +191,19 @@ function toHebrew(num) {
return letters.slice(0, -1).join('') + HEB_GERSHAYIM + letters[letters.length - 1];
}
export function generateChoices(correctAnswer, allRanges, count = 3) {
export function generateChoices(correctAnswer, allRanges, count = 3, matchLastDigit = false) {
const choices = new Set([correctAnswer]);
const [min, max] = allRanges;
const useLastDigit = matchLastDigit && correctAnswer > 10;
let attempts = 0;
while (choices.size < count && attempts < 100) {
let wrong;
const offset = Math.floor(Math.random() * 20) + 1;
if (Math.random() < 0.5) {
wrong = correctAnswer + offset;
if (useLastDigit) {
const offset = (Math.floor(Math.random() * 20) + 1) * 10;
wrong = Math.random() < 0.5 ? correctAnswer + offset : correctAnswer - offset;
} else {
wrong = correctAnswer - offset;
const offset = Math.floor(Math.random() * 20) + 1;
wrong = Math.random() < 0.5 ? correctAnswer + offset : correctAnswer - offset;
}
if (wrong >= min && wrong <= max && wrong !== correctAnswer) {
choices.add(wrong);
@@ -209,7 +211,14 @@ export function generateChoices(correctAnswer, allRanges, count = 3) {
attempts++;
}
while (choices.size < count) {
const r = min + Math.floor(Math.random() * (max - min + 1));
let r;
if (useLastDigit) {
do {
r = min + Math.floor(Math.random() * (max - min + 1));
} while (r % 10 !== correctAnswer % 10 && choices.size < count + 50);
} else {
r = min + Math.floor(Math.random() * (max - min + 1));
}
choices.add(r);
}
const arr = Array.from(choices);
+1 -1
View File
@@ -1,4 +1,4 @@
const CACHE_NAME = 'numnum-v37';
const CACHE_NAME = 'numnum-v38';
const ASSETS = [
'/',
'/index.html',