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} {finish?.answer}
</div> </div>
</div>} </div>}
<div className="mt-3"> <div className="my-3">
<ActionButtons /> <ActionButtons />
</div> </div>
</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."}, {"ts":1527812661,"i":13938,"p":"هلک","f":"halík, halúk","g":"halik,haluk","e":"boy, young lad","c":"n. m. anim."},
].filter(tp.isNounEntry); ].filter(tp.isNounEntry);
const persons = [ const persons: T.Person[] = [
T.Person.FirstSingMale, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
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 secondPersons = [ const secondPersons = [

View File

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