fixed pool

This commit is contained in:
lingdocs 2022-09-03 17:00:06 +04:00
parent e0ce0ca74e
commit dc11ad71bb
3 changed files with 13 additions and 22 deletions

View File

@ -226,7 +226,7 @@ function GameCore<T>({ inChapter, questions, Display, timeLimit, Instructions, s
{finish?.answer}
</div>
</div>}
<div className="mt-3">
<div className="my-3">
<ActionButtons />
</div>
</div>}

View File

@ -75,19 +75,8 @@ const nouns: T.NounEntry[] = [
{"ts":1527812661,"i":13938,"p":"هلک","f":"halík, halúk","g":"halik,haluk","e":"boy, young lad","c":"n. m. anim."},
].filter(tp.isNounEntry);
const persons = [
T.Person.FirstSingMale,
T.Person.FirstSingFemale,
T.Person.SecondSingMale,
T.Person.SecondSingFemale,
T.Person.ThirdSingMale,
T.Person.ThirdSingFemale,
T.Person.FirstPlurMale,
T.Person.FirstPlurFemale,
T.Person.SecondPlurMale,
T.Person.SecondPlurFemale,
T.Person.ThirdPlurMale,
T.Person.ThirdPlurFemale,
const persons: T.Person[] = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
];
const secondPersons = [

View File

@ -11,6 +11,7 @@ import { randFromArray } from "@lingdocs/pashto-inflector";
export function makePool<P>(poolBase: P[], removalLaxity = 0): () => P {
let pool = [...poolBase];
function shouldStillKeepIt() {
if (!removalLaxity) return false;
return Math.random() < (removalLaxity / 100);
}
function pickRandomFromPool(): P {
@ -18,14 +19,15 @@ export function makePool<P>(poolBase: P[], removalLaxity = 0): () => P {
const pick = randFromArray(pool);
// Remove the (first occurance of) the item from the pool
// This step might be skipped if the removal laxity is set
if (removalLaxity && !shouldStillKeepIt()) {
const index = pool.findIndex(v => matches(v, pick))
if (index === -1) throw new Error("could not find pick from pool");
pool.splice(index, 1);
// If the pool is empty, reset it
if (pool.length === 0) {
pool = [...poolBase];
}
if (shouldStillKeepIt()) {
return pick;
}
const index = pool.findIndex(v => matches(v, pick))
if (index === -1) throw new Error("could not find pick from pool");
pool.splice(index, 1);
// If the pool is empty, reset it
if (pool.length === 0) {
pool = [...poolBase];
}
return pick;
}