Parse guesses instead of hardcoding them

This commit is contained in:
Austin Chen 2022-02-13 22:48:19 -08:00
parent e6df0633bf
commit 2c11ce9efa

View File

@ -1,3 +1,4 @@
import { useState } from 'react'
import { Page } from '../../components/page' import { Page } from '../../components/page'
import { Title } from '../../components/title' import { Title } from '../../components/title'
// From https://github.com/lynn/hello-wordl // From https://github.com/lynn/hello-wordl
@ -11,15 +12,10 @@ export default function Wordle() {
// const dict = dictionary.filter((word) => word.length === WORD_LENGTH) // const dict = dictionary.filter((word) => word.length === WORD_LENGTH)
const words = targets.filter((word) => word.length === WORD_LENGTH) const words = targets.filter((word) => word.length === WORD_LENGTH)
const pastGuesses: PastGuess[] = [ const [input, setInput] = useState('')
// From https://hellowordl.net/?challenge=aGFyZHk
// { guess: 'sheep', result: 'BYBBB' }, const pastGuesses: PastGuess[] = parsePastGuesses(input)
// { guess: 'butch', result: 'BBBBY' }, const placeholder = 'e.g.\nstage BBYBB\nlucre YYGYY'
// { guess: 'hydra', result: 'GYYYY' },
// Answer: hardy
{ guess: 'snowy', result: 'BBBYB' },
{ guess: 'wheel', result: 'GYBBB' },
]
const valids = validHardMode(words, pastGuesses) const valids = validHardMode(words, pastGuesses)
@ -34,7 +30,12 @@ export default function Wordle() {
Actually for{' '} Actually for{' '}
<a href="https://hellowordl.net/">https://hellowordl.net/</a> <a href="https://hellowordl.net/">https://hellowordl.net/</a>
<p>Past guesses:</p> <p>Past guesses:</p>
<pre>{JSON.stringify(pastGuesses, null, 2)}</pre> <textarea
className="h-32 w-full p-2"
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder={placeholder}
/>
<br /> <br />
<br /> <br />
<p className="text-black"> <p className="text-black">
@ -98,11 +99,17 @@ function validHardMode(wordlist: string[], pastGuesses: PastGuess[]) {
} }
function parsePastGuesses(pastGuesses: string) { function parsePastGuesses(pastGuesses: string) {
return pastGuesses.split('\n').map((pg) => { return pastGuesses
const [guess, result] = pg.split(', ') .split('\n')
return { guess, result } .map((pg) => {
}) const [guess, result] = pg.split(' ')
return { guess, result }
})
.filter(({ guess, result }) => guess && result)
} }
// Bad target words: witan, sedum // Bad target words: witan, sedum
// TODO: Maybe just use canonical Wordle dictionaries // TODO: Maybe just use canonical Wordle dictionaries
// DEBUG: { guess: 'lucre', result: 'YYGYY' }
// Should produce: ulcer