Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature / Changes to make easier levels [44] #61

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -33,14 +33,35 @@ function App() {
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches;
const [dark, setDark] = useSetting<boolean>("dark", prefersDark);
const [difficulty, setDifficulty] = useSetting<number>("difficulty", 2);
const [titleFormat, setTitleFormat] = useState<string>("inherit");
const [colorBlind, setColorBlind] = useSetting<boolean>("colorblind", false);
const [difficulty, setDifficulty] = useSetting<number>("difficulty", 0);
const [keyboard, setKeyboard] = useSetting<string>(
"keyboard",
"qwertyuiop-asdfghjkl-BzxcvbnmE"
);
const [enterLeft, setEnterLeft] = useSetting<boolean>("enter-left", false);

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" : "";
setTimeout(() => {
Expand All @@ -66,8 +87,9 @@ function App() {
<h1>
<span
style={{
color: difficulty > 0 ? "#e66" : "inherit",
fontStyle: difficulty > 1 ? "italic" : "inherit",
color: titleFormat,
fontStyle:
difficulty === Difficulty.UltraHard ? "italic" : "inherit",
}}
>
hell
Expand Down Expand Up @@ -130,13 +152,16 @@ function App() {
id="difficulty-setting"
type="range"
min="0"
max="2"
max="4"
value={difficulty}
onChange={(e) => setDifficulty(+e.target.value)}
/>
<div>
<label htmlFor="difficulty-setting">Difficulty:</label>
<strong>{["Normal", "Hard", "Ultra Hard"][difficulty]}</strong>
&nbsp;
<strong>
{["Baby", "Easy", "Normal", "Hard", "Ultra Hard"][difficulty]}
</strong>
<div
style={{
fontSize: 14,
Expand All @@ -147,6 +172,8 @@ function App() {
>
{
[
`Guesses don't even need to be real words.`,
`Guesses must be valid dictionary words. Easy mode.`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s describe what exactly makes this “easy mode”.

Suggested change
`Guesses must be valid dictionary words. Easy mode.`,
`Guesses must be valid dictionary words. Easy mode – the target word will be a common word.`,

`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.`,
Expand Down
15 changes: 9 additions & 6 deletions src/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ interface GameProps {
keyboardLayout: string;
}

const easyTargets = targetList.slice(0, targetList.indexOf("revel") + 1); // Slightly more frequent word on the list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“revel” is currently on line 14279 of the wordlist, while “murky” is on line 14502. I don’t think removing 223 possible words out of 14501 will produce a noticeable difference in difficulty. How about halving the search space by splitting on a word around line 7000?

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);
Expand Down Expand Up @@ -79,7 +81,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<HTMLTableElement>(null);
Expand All @@ -92,7 +94,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("");
Expand Down Expand Up @@ -145,7 +147,8 @@ function Game(props: GameProps) {
setHint("Too short");
return;
}
if (!dictionary.includes(currentGuess)) {

if (props.difficulty !== Difficulty.Baby && !dictionary.includes(currentGuess)) {
setHint("Not a valid word");
return;
}
Expand Down Expand Up @@ -246,7 +249,7 @@ function Game(props: GameProps) {
setGameState(GameState.Playing);
setGuesses([]);
setCurrentGuess("");
setTarget(randomTarget(length));
setTarget(randomTarget(length, props.difficulty));
setWordLength(length);
setHint(`${length} letters`);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/clue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import dictionary from "./dictionary.json";

export enum Difficulty {
Baby,
Easy,
Normal,
Hard,
UltraHard,
Expand Down