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", "@formkit/auto-animate": "^1.0.0-beta.1",
"@fortawesome/fontawesome-free": "^5.15.4", "@fortawesome/fontawesome-free": "^5.15.4",
"@lingdocs/lingdocs-main": "^0.3.1", "@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/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0", "@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10", "@testing-library/user-event": "^12.1.10",

View File

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

View File

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

View File

@ -1,6 +1,10 @@
import { import {
removeAccents, removeAccents,
hasAccents, hasAccents,
Types as T,
standardizePashto,
standardizePhonetics,
flattenLengths,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
export function makeRandomQs<Q>( export function makeRandomQs<Q>(
@ -40,4 +44,15 @@ export function makeProgress(i: number, total: number): Progress {
*/ */
export function compareF(input: string, answer: string): boolean { export function compareF(input: string, answer: string): boolean {
return input === (hasAccents(input) ? answer : removeAccents(answer)); 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" rambda "^6.7.0"
react-select "^5.2.2" react-select "^5.2.2"
"@lingdocs/pashto-inflector@^2.6.7": "@lingdocs/pashto-inflector@^2.6.8":
version "2.6.7" version "2.6.8"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.6.7.tgz#0b40b96772ec0bee284af711b017b86e2175c9ef" resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.6.8.tgz#d104620a75a4f034d3dcd9d8a097eab40b77024d"
integrity sha512-wXRCkZc2+H+MkMx1gka2iABHWBxPuz96gcNMTtxPFF/cJSP6pIMmTNXgFgjbSXK3frHteJGvnBaISnAQ05J7wg== integrity sha512-z2RetX9mRgZxM0FIX8R3cgCF+Exof/OigMDZIlEHLhBAljSwaojA9ZdXnyKP1zW8EDtjLIqsr3rWQre6niU80w==
dependencies: dependencies:
"@formkit/auto-animate" "^1.0.0-beta.1" "@formkit/auto-animate" "^1.0.0-beta.1"
classnames "^2.2.6" classnames "^2.2.6"