improved games - ability to check phonetics and 3 strikes

This commit is contained in:
lingdocs 2022-05-30 15:29:24 -05:00
parent c64e48d274
commit f4dc09e941
5 changed files with 25 additions and 20 deletions

View File

@ -6,7 +6,7 @@
"@formkit/auto-animate": "^1.0.0-beta.1",
"@fortawesome/fontawesome-free": "^5.15.4",
"@lingdocs/lingdocs-main": "^0.3.1",
"@lingdocs/pashto-inflector": "^2.6.7",
"@lingdocs/pashto-inflector": "^2.6.8",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",

View File

@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import {
comparePs,
makeProgress,
} from "../../lib/game-utils";
import GameCore from "../GameCore";
@ -7,7 +8,6 @@ import {
Types as T,
Examples,
defaultTextOptions as opts,
standardizePashto,
typePredicates as tp,
makeNounSelection,
randFromArray,
@ -277,9 +277,8 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st
return;
}
e.preventDefault();
const given = standardizePashto(answer.trim());
const correct = checkAnswer(given, question.equative.ps)
&& withBa === question.equative.hasBa;
const correct = comparePs(answer, question.equative.ps)
&& (withBa === question.equative.hasBa);
if (correct) {
setAnswer("");
}
@ -467,11 +466,6 @@ function humanReadableTense(tense: T.EquativeTense | "allProduce"): string {
: tense;
}
function checkAnswer(given: string, answer: T.SingleOrLengthOpts<T.PsString[]>): boolean {
const possible = flattenLengths(answer);
return possible.some(x => given === x.p);
}
function makeEPS(subject: T.NPSelection, predicate: T.AdjectiveEntry | T.LocativeAdverbEntry, tense: T.EquativeTense): T.EPSelectionComplete {
return {
blocks: [

View File

@ -1,7 +1,7 @@
import { useState } from "react";
import {
makeProgress,
compareF,
comparePs,
} from "../../lib/game-utils";
import genderColors from "../../lib/gender-colors";
import GameCore from "../GameCore";
@ -10,7 +10,6 @@ import {
Examples,
defaultTextOptions as opts,
inflectWord,
standardizePashto,
firstVariation,
typePredicates as tp,
randFromArray,
@ -76,12 +75,9 @@ export default function UnisexNounGame({ id, link }: { id: string, link: string
}
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const given = standardizePashto(answer.trim());
// @ts-ignore
const correctAnswer = inflections[flipGender(question.gender)][0];
const correct = correctAnswer.some((ps: T.PsString) => (
(given === ps.p) || compareF(given, ps.f)
));
const correct = comparePs(answer, correctAnswer);
if (correct) {
setAnswer("");
}

View File

@ -1,6 +1,10 @@
import {
removeAccents,
hasAccents,
Types as T,
standardizePashto,
standardizePhonetics,
flattenLengths,
} from "@lingdocs/pashto-inflector";
export function makeRandomQs<Q>(
@ -41,3 +45,14 @@ export function makeProgress(i: number, total: number): Progress {
export function compareF(input: string, answer: string): boolean {
return input === (hasAccents(input) ? answer : removeAccents(answer));
}
export function comparePs(input: string, answer: T.SingleOrLengthOpts<T.PsString | T.PsString[]>): boolean {
if ("long" in answer) {
return comparePs(input, flattenLengths(answer))
}
if (Array.isArray(answer)) {
return answer.some(a => comparePs(input, a));
}
const stand = standardizePhonetics(standardizePashto(input)).trim();
return stand === answer.p || compareF(stand, answer.f);
}

View File

@ -1695,10 +1695,10 @@
rambda "^6.7.0"
react-select "^5.2.2"
"@lingdocs/pashto-inflector@^2.6.7":
version "2.6.7"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.6.7.tgz#0b40b96772ec0bee284af711b017b86e2175c9ef"
integrity sha512-wXRCkZc2+H+MkMx1gka2iABHWBxPuz96gcNMTtxPFF/cJSP6pIMmTNXgFgjbSXK3frHteJGvnBaISnAQ05J7wg==
"@lingdocs/pashto-inflector@^2.6.8":
version "2.6.8"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.6.8.tgz#d104620a75a4f034d3dcd9d8a097eab40b77024d"
integrity sha512-z2RetX9mRgZxM0FIX8R3cgCF+Exof/OigMDZIlEHLhBAljSwaojA9ZdXnyKP1zW8EDtjLIqsr3rWQre6niU80w==
dependencies:
"@formkit/auto-animate" "^1.0.0-beta.1"
classnames "^2.2.6"