fixed pool
This commit is contained in:
parent
e0ce0ca74e
commit
dc11ad71bb
|
@ -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>}
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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,7 +19,9 @@ 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()) {
|
||||
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);
|
||||
|
@ -26,7 +29,6 @@ export function makePool<P>(poolBase: P[], removalLaxity = 0): () => P {
|
|||
if (pool.length === 0) {
|
||||
pool = [...poolBase];
|
||||
}
|
||||
}
|
||||
return pick;
|
||||
}
|
||||
return pickRandomFromPool;
|
||||
|
|
Loading…
Reference in New Issue