Avoid immediate repeat of last fact when picking next question
This commit is contained in:
parent
53d140caf8
commit
bf1e1238fc
30
app.js
30
app.js
@ -71,7 +71,8 @@
|
|||||||
activeSkin: 'skin-default', activeTrail: '', activeBackground: 'bg-default',
|
activeSkin: 'skin-default', activeTrail: '', activeBackground: 'bg-default',
|
||||||
activePet: '', activePetIcon: '',
|
activePet: '', activePetIcon: '',
|
||||||
studentName: '',
|
studentName: '',
|
||||||
focusQueue: []
|
focusQueue: [],
|
||||||
|
lastFactId: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
let game = {
|
let game = {
|
||||||
@ -185,22 +186,35 @@
|
|||||||
const relevantTrouble = state.troubleList.filter(t => allowedNumbers.includes(t.n1) || allowedNumbers.includes(t.n2));
|
const relevantTrouble = state.troubleList.filter(t => allowedNumbers.includes(t.n1) || allowedNumbers.includes(t.n2));
|
||||||
|
|
||||||
let n1, n2;
|
let n1, n2;
|
||||||
|
const makeId = (a, b) => {
|
||||||
|
const [s, l] = a < b ? [a, b] : [b, a];
|
||||||
|
return `${s}x${l}`;
|
||||||
|
};
|
||||||
|
const lastId = state.lastFactId;
|
||||||
|
|
||||||
if (state.focusQueue.length > 0) {
|
if (state.focusQueue.length > 0) {
|
||||||
const factId = state.focusQueue.shift();
|
const factId = state.focusQueue.shift();
|
||||||
const parts = factId.split('x').map(Number);
|
const parts = factId.split('x').map(Number);
|
||||||
[n1, n2] = parts;
|
[n1, n2] = parts;
|
||||||
} else {
|
} else {
|
||||||
if (relevantTrouble.length > 0 && Math.random() < 0.5) {
|
let attempts = 0;
|
||||||
const struggle = relevantTrouble[Math.floor(Math.random() * relevantTrouble.length)];
|
while (attempts < 6) {
|
||||||
n1 = struggle.n1; n2 = struggle.n2;
|
if (relevantTrouble.length > 0 && Math.random() < 0.5) {
|
||||||
} else {
|
const struggle = relevantTrouble[Math.floor(Math.random() * relevantTrouble.length)];
|
||||||
n1 = allowedNumbers[Math.floor(Math.random() * allowedNumbers.length)];
|
n1 = struggle.n1; n2 = struggle.n2;
|
||||||
n2 = Math.floor(Math.random() * 12) + 1;
|
} else {
|
||||||
if (Math.random() > 0.5) [n1, n2] = [n2, n1];
|
n1 = allowedNumbers[Math.floor(Math.random() * allowedNumbers.length)];
|
||||||
|
n2 = Math.floor(Math.random() * 12) + 1;
|
||||||
|
if (Math.random() > 0.5) [n1, n2] = [n2, n1];
|
||||||
|
}
|
||||||
|
const cid = makeId(n1, n2);
|
||||||
|
if (cid !== lastId || attempts === 5) break;
|
||||||
|
attempts++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
game.currentFact = { n1, n2, ans: n1 * n2 };
|
game.currentFact = { n1, n2, ans: n1 * n2 };
|
||||||
|
state.lastFactId = makeId(n1, n2);
|
||||||
document.getElementById('equation-display').innerText = `${n1} × ${n2}`;
|
document.getElementById('equation-display').innerText = `${n1} × ${n2}`;
|
||||||
startDementor();
|
startDementor();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user