From 10915e37283b3a1425d0b5b50ee377cf3b1f96f9 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Tue, 10 May 2022 16:48:13 -0500 Subject: [PATCH] more games --- src/games/GameCore.tsx | 6 +- src/games/games.tsx | 8 + src/games/sub-cores/EquativeGame.tsx | 220 ++++++++++++++++++++++----- src/games/sub-cores/GenderGame.tsx | 2 +- src/user-context.tsx | 2 +- 5 files changed, 194 insertions(+), 44 deletions(-) diff --git a/src/games/GameCore.tsx b/src/games/GameCore.tsx index 65f9dd2..fc0cad4 100644 --- a/src/games/GameCore.tsx +++ b/src/games/GameCore.tsx @@ -149,7 +149,7 @@ function GameCore({ questions, Display, timeLimit, Instructions, studyLink, i /> } - +
{finish === undefined && (current @@ -176,7 +176,9 @@ function GameCore({ questions, Display, timeLimit, Instructions, studyLink, i

{failMessage(current?.progress, finish)}

{typeof finish === "object" &&
The correct answer was:
- {finish?.answer} +
+ {finish?.answer} +
}
diff --git a/src/games/games.tsx b/src/games/games.tsx index 5b465b4..1c60af0 100644 --- a/src/games/games.tsx +++ b/src/games/games.tsx @@ -91,6 +91,13 @@ export const equativeGameAllIdentify = makeGameRecord( (id, link) => () => , ); +export const equativeGameSituations = makeGameRecord( + "Choose the right equative for the situation", + "equative-past-situations", + "/equatives/other-equatives", + (id, link) => () => , +); + export const equativeGameAllProduce = makeGameRecord( "Write the equative (all tenses)", "equative-past-summary-produce", @@ -117,6 +124,7 @@ const games: { chapter: string, items: GameRecord[] }[] = [ equativeGamePast, equativeGameWouldBe, equativeGamePastSubjunctive, + equativeGameSituations, equativeGameAllIdentify, equativeGameAllProduce, ], diff --git a/src/games/sub-cores/EquativeGame.tsx b/src/games/sub-cores/EquativeGame.tsx index 40c1708..fe919e5 100644 --- a/src/games/sub-cores/EquativeGame.tsx +++ b/src/games/sub-cores/EquativeGame.tsx @@ -57,13 +57,126 @@ const tenses: T.EquativeTense[] = [ "present", "habitual", "subjunctive", "future", "past", "wouldBe", "pastSubjunctive", ]; -const amount = 16; -const timeLimit = 75; +type Situation = { + description: string | JSX.Element, + tense: T.EquativeTense[], +}; +const situations: Situation[] = [ + { + description: <>A is B, for sure, right now, + tense: ["present"], + }, + { + description: <>A is probably B, right now, + tense: ["future"], + }, + { + description: <>A will be B in the future, + tense: ["future"], + }, + { + description: <>We can assume that A is most likely B, + tense: ["future"], + }, + { + description: <>You know A is B, currently, + tense: ["present"], + }, + { + description: <>A tends to be B, + tense: ["habitual"], + }, + { + description: <>A is usually B, + tense: ["habitual"], + }, + { + description: <>A is generally B, + tense: ["habitual"], + }, + { + description: <>A is B, right now, + tense: ["present"], + }, + { + description: <>A is always B, as a matter of habit, + tense: ["present"], + }, + { + description: "It's a good thing for A to be B", + tense: ["subjunctive"], + }, + { + description: "A needs to be B (out of obligation/necessity)", + tense: ["subjunctive"], + }, + { + description: "You hope that A is B", + tense: ["subjunctive"], + }, + { + description: "You desire A to be B", + tense: ["subjunctive"], + }, + { + description: "If A is B ...", + tense: ["subjunctive"], + }, + { + description: "...so that A will be B (a purpose)", + tense: ["subjunctive"], + }, + { + description: "A was definately B", + tense: ["past"], + }, + { + description: "A was B", + tense: ["past"], + }, + { + description: "A was probably B in the past", + tense: ["wouldBe"], + }, + { + description: "A used to be B (habitually, repeatedly)", + tense: ["wouldBe"], + }, + { + description: "assume that A would have probably been B", + tense: ["wouldBe"], + }, + { + description: "under different circumstances, A would have been B", + tense: ["wouldBe", "pastSubjunctive"], + }, + { + description: "You wish A were B (but it's not)", + tense: ["pastSubjunctive"], + }, + { + description: "If A were B (but it's not)", + tense: ["pastSubjunctive"], + }, + { + description: "Aaagh! If only A were B!", + tense: ["pastSubjunctive"], + }, + { + description: "A should have been B!", + tense: ["pastSubjunctive", "wouldBe"], + }, +]; + +const amount = 20; +const timeLimit = 90; type Question = { EPS: T.EPSelectionComplete, phrase: { ps: T.PsString[], e?: string[] }, equative: T.EquativeRendered, +} | { + situation: Situation, }; const pronounTypes = [ @@ -76,12 +189,12 @@ const pronounTypes = [ [T.Person.ThirdPlurMale, T.Person.ThirdPlurFemale], ]; -export default function EquativeGame({ id, link, level }: { id: string, link: string, level: T.EquativeTense | "allProduce" | "allIdentify" }) { +export default function EquativeGame({ id, link, level }: { id: string, link: string, level: T.EquativeTense | "allProduce" | "allIdentify" | "situations" }) { function* questions (): Generator> { let pool = [...pronounTypes]; + let situationPool = [...situations]; function makeRandPronoun(): T.PronounSelection { let person: T.Person; - console.log(pool); do { person = randomPerson(); // eslint-disable-next-line @@ -104,7 +217,7 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st number: n.numberCanChange ? randFromArray(["singular", "plural"]) : n.number, }; } - function makeRandomEPS(): T.EPSelectionComplete { + function makeRandomEPS(l: T.EquativeTense | "allIdentify" | "allProduce"): T.EPSelectionComplete { const subj = randFromArray([ makeRandPronoun, makeRandPronoun, @@ -112,31 +225,43 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st makeRandPronoun, ])(); const pred = randFromArray([...adjectives, ...locAdverbs]); - const tense = (level === "allIdentify" || level === "allProduce") + const tense = (l === "allIdentify" || l === "allProduce") ? randFromArray(tenses) - : level; + : l; return makeEPS(subj, pred, tense); } for (let i = 0; i < amount; i++) { - const EPS = makeRandomEPS(); - const EP = renderEP(EPS); - const compiled = compileEP( - EP, - true, - level === "allIdentify" ? undefined : { equative: true, kidsSection: true }, - ); - const phrase = { - ps: compiled.ps, - e: level === "allIdentify" ? undefined : compiled.e, - }; - yield { - progress: makeProgress(i, amount), - question: { - EPS, - phrase, - equative: EP.equative, - }, - }; + if (level === "situations") { + const picked = randFromArray(situationPool); + situationPool = situationPool.filter(x => picked.description !== x.description); + if (situationPool.length === 0) situationPool = [...situations]; + yield { + progress: makeProgress(i, amount), + question: { + situation: picked, + }, + }; + } else { + const EPS = makeRandomEPS(level); + const EP = renderEP(EPS); + const compiled = compileEP( + EP, + true, + level === "allIdentify" ? undefined : { equative: true, kidsSection: true }, + ); + const phrase = { + ps: compiled.ps, + e: level === "allIdentify" ? undefined : compiled.e, + }; + yield { + progress: makeProgress(i, amount), + question: { + EPS, + phrase, + equative: EP.equative, + }, + }; + } }; } @@ -148,6 +273,9 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st setAnswer(value); } const handleSubmit = (e: React.FormEvent) => { + if ("situation" in question) { + return; + } e.preventDefault(); const given = standardizePashto(answer.trim()); const correct = checkAnswer(given, question.equative.ps) @@ -158,6 +286,15 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st callback(!correct ? makeCorrectAnswer(question) : true); } const handleTenseIdentify = (tense: T.EquativeTense) => { + if ("situation" in question) { + const wasCorrect = question.situation.tense.includes(tense); + if (wasCorrect) { + callback(true); + } else { + callback(makeCorrectAnswer(question)); + } + return; + } const renderedWAnswer = renderEP({ ...question.EPS, equative: { @@ -186,7 +323,7 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st )); }); callback(
- {makeCorrectTenseAnswer(possibleCorrect)} + {possibleCorrect.map(humanReadableTense).join(" or ")}
) } } @@ -195,13 +332,15 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st }, [question]); return
- {level === "allIdentify" ? + {(level === "allIdentify" || level === "situations") ?
- + {"situation" in question ?

+ {question.situation.description} +

: {randFromArray(question.phrase.ps)} - +
}
- :
+ : !("situation" in question) &&
{/* @ts-ignore TODO: REMOVE AS P_INFLE */} {modExs(question.phrase.ps, withBa)[0]} @@ -212,9 +351,9 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st
{humanReadableTense(question.EPS.equative.tense)} equative
} - {level === "allIdentify" ?
+ {level === "allIdentify" || "situation" in question ?
- {tenses.map(t =>
+ {tenses.map(t =>
@@ -280,15 +421,14 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st /> }; -function makeCorrectTenseAnswer(tenses: T.EquativeTense[]): string { - return tenses.reduce((accum, curr, i) => ( - `${accum}${(i > 0 ? " or " : " ")}'${humanReadableTense(curr)}'` - ), ""); -} - function makeCorrectAnswer(question: Question): JSX.Element { + if ("situation" in question) { + return
+ {question.situation.tense.map(humanReadableTense).join(" or ")} +
; + } return
-
+
{flattenLengths(question.equative.ps).reduce(((accum, curr, i): JSX.Element[] => ( [ ...accum, diff --git a/src/games/sub-cores/GenderGame.tsx b/src/games/sub-cores/GenderGame.tsx index 94586f2..ed6c81f 100644 --- a/src/games/sub-cores/GenderGame.tsx +++ b/src/games/sub-cores/GenderGame.tsx @@ -114,7 +114,7 @@ export default function GenderGame({level, id, link }: { level: 1 | 2, id: strin const nounGender: T.Gender = nounNotIn(mascNouns)(question) ? "fem" : "masc"; const correct = gender === nounGender; callback(!correct - ?
+ ?
diff --git a/src/user-context.tsx b/src/user-context.tsx index 437ccb7..aa88995 100644 --- a/src/user-context.tsx +++ b/src/user-context.tsx @@ -36,7 +36,7 @@ function UserProvider({ children }: any) { }).catch(console.error); } - const checkUserCronJob = new CronJob("1/30 * * * * *", () => { + const checkUserCronJob = new CronJob("10 * * * *", () => { pullUser(); if (value) { postSavedResults(value.userId);