From 7ce90dc0693d078da6fec9ae2a4a0c8410c6f703 Mon Sep 17 00:00:00 2001 From: Daniel Kunkler Date: Mon, 24 Jan 2022 23:08:52 -0600 Subject: [PATCH] Changes to make easier levels --- src/App.tsx | 38 ++++++++++++++++++++++++++++++++------ src/Game.tsx | 16 ++++++++++------ src/clue.ts | 2 +- src/util.ts | 2 ++ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d1ba9e5..5b7bc6c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import "./App.css"; -import { maxGuesses, seed } from "./util"; +import { Difficulty, maxGuesses, seed } from "./util"; import Game from "./Game"; import { useEffect, useState } from "react"; import { About } from "./About"; @@ -33,7 +33,28 @@ function App() { window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; const [dark, setDark] = useSetting("dark", prefersDark); - const [difficulty, setDifficulty] = useSetting("difficulty", 0); + const [difficulty, setDifficulty] = useSetting("difficulty", 2); + const [titleFormat, setTitleFormat] = useState("inherit"); + + useEffect(() => { + switch (difficulty) { + case 0: + setTitleFormat("#23eb2a"); + break; + case 1: + setTitleFormat("#94eb97"); + break; + case 2: + setTitleFormat("inherit"); + break; + case 3: + case 4: + setTitleFormat("#e66"); + break; + default: + setTitleFormat("inherit"); + } + }, [difficulty]); useEffect(() => { document.body.className = dark ? "dark" : ""; @@ -60,8 +81,9 @@ function App() {

0 ? "#e66" : "inherit", - fontStyle: difficulty > 1 ? "italic" : "inherit", + color: titleFormat, + fontStyle: + difficulty === Difficulty.UltraHard ? "italic" : "inherit", }} > hell @@ -115,14 +137,16 @@ function App() { id="difficulty-setting" type="range" min="0" - max="2" + max="4" value={difficulty} onChange={(e) => setDifficulty(+e.target.value)} />
  - {["Normal", "Hard", "Ultra Hard"][difficulty]} + + {["Baby", "Easy", "Normal", "Hard", "Ultra Hard"][difficulty]} +
{ [ + `Guesses don't even need to be real words.`, + `Guesses must be valid dictionary words. Easy mode.`, `Guesses must be valid dictionary words.`, `Wordle's "Hard Mode". Green letters must stay fixed, and yellow letters must be reused.`, `An even stricter Hard Mode. Yellow letters must move away from where they were clued, and gray clues must be obeyed.`, diff --git a/src/Game.tsx b/src/Game.tsx index d30457a..6166f31 100644 --- a/src/Game.tsx +++ b/src/Game.tsx @@ -27,12 +27,14 @@ interface GameProps { difficulty: Difficulty; } +const easyTargets = targetList.slice(0, targetList.indexOf("revel") + 1); // Slightly more frequent word on the list const targets = targetList.slice(0, targetList.indexOf("murky") + 1); // Words no rarer than this one const minWordLength = 4; const maxWordLength = 11; -function randomTarget(wordLength: number): string { - const eligible = targets.filter((word) => word.length === wordLength); +function randomTarget(wordLength: number, difficulty: number): string { + const target = difficulty < Difficulty.Normal ? easyTargets : targets; + const eligible = target.filter((word) => word.length === wordLength); let candidate: string; do { candidate = pick(eligible); @@ -77,7 +79,7 @@ function Game(props: GameProps) { ); const [target, setTarget] = useState(() => { resetRng(); - return challenge || randomTarget(wordLength); + return challenge || randomTarget(wordLength, props.difficulty); }); const [gameNumber, setGameNumber] = useState(1); const tableRef = useRef(null); @@ -90,7 +92,7 @@ function Game(props: GameProps) { const newWordLength = wordLength < minWordLength || wordLength > maxWordLength ? 5 : wordLength; setWordLength(newWordLength); - setTarget(randomTarget(newWordLength)); + setTarget(randomTarget(newWordLength, props.difficulty)); setGuesses([]); setCurrentGuess(""); setHint(""); @@ -143,7 +145,9 @@ function Game(props: GameProps) { setHint("Too short"); return; } - if (!dictionary.includes(currentGuess)) { + + // Baby will short circuit to false + if (props.difficulty && !dictionary.includes(currentGuess)) { setHint("Not a valid word"); return; } @@ -244,7 +248,7 @@ function Game(props: GameProps) { setGameState(GameState.Playing); setGuesses([]); setCurrentGuess(""); - setTarget(randomTarget(length)); + setTarget(randomTarget(length, props.difficulty)); setWordLength(length); setHint(`${length} letters`); }} diff --git a/src/clue.ts b/src/clue.ts index aeed2e1..074b6ca 100644 --- a/src/clue.ts +++ b/src/clue.ts @@ -63,7 +63,7 @@ export function violation( clues: CluedLetter[], guess: string ): string | undefined { - if (difficulty === Difficulty.Normal) { + if (difficulty <= Difficulty.Normal) { return undefined; } const ultra = difficulty === Difficulty.UltraHard; diff --git a/src/util.ts b/src/util.ts index 289799b..3a43a97 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,6 +1,8 @@ import dictionary from "./dictionary.json"; export enum Difficulty { + Baby, + Easy, Normal, Hard, UltraHard,