-
Notifications
You must be signed in to change notification settings - Fork 231
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
dskunkler
wants to merge
4
commits into
lynn:main
Choose a base branch
from
dskunkler:dskunkler/feature44
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,12 +29,14 @@ interface GameProps { | |
keyboardLayout: string; | ||
} | ||
|
||
const easyTargets = targetList.slice(0, targetList.indexOf("revel") + 1); // Slightly more frequent word on the list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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); | ||
|
@@ -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(""); | ||
|
@@ -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; | ||
} | ||
|
@@ -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`); | ||
}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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”.