- apply the structure of the first element to the others: highlight takes an array of letters, validation is an unquoted function, examples is a list of words. { round: 1, title: "starts with HI", highlight: ["H", "I"], validation: str => /^hi.*/.test(str.toLowerCase()), unselectable_keys: [], examples: ["hit", "hint", "hill",] },
- make this array exportable.
- import the rounds array in the App component to use for the rounds of the game.
- leverage the other features of the rounds data:
- the examples should be between the prompt and the currentGuess
- in the currentGuess, on the keyboard, and in the displayex examples, the letters in round.highlight should be visually distinct from the the other letters.
- the submit button should only be clickable if validation returns true.
- make the unselectable keys unselectable. With keyboard input, typing an unselectable letter doesn't do anything
Help me begin to build out the postGame view:
- during the game, record the list of words the player submitted.
- upon submitting the final guess, send that data to the backend.
- we will validate that submissions are actual words on the backend. Skip the actual validation for now. instead use a stub that says every submission has a 75% change of being valid. Do this on the backend.
- the postGame state should present a table of the results, that lists each word.
- if it the word is valid, list the number of letters in it.
- visually indicate valid and invalid words using versions of red and green that are discernible for standard colorblindness.
- the last line of the table should a "total" that sums up the letters in all valid words.
help me devise a good strategy for validation. Currently, I have a list of valid words in a table format.
-
create a database initialization script that loads the csv into sql.
-
update the project readme with instructions to run the this initialization (so the project is easy to remix)
-
update the validation logic build earlier in the conversation.
-
below the first few lines of the csv.
-
A version currently lives at https://gist.githubusercontent.com/a-lexwein/e3e6a0817c71d57c063c238f519f8b45/raw/9a06a1e2f5e4c479bb653ff39dbb65f77cd60cff/thinkOfWords.csv
id,rule,word,n_letters
1,starts with HI,histocompatibilities,20
1,starts with HI,histopathologically,19
1,starts with HI,historiographically,19
1,starts with HI,histocompatibility,18
don't suggest code changes yet, instead, build out a strategy in markdown that I can freshly prompt townie with.
Put that prompt immediately below here in this file todo.md:
This is a word game where players must think of the biggest word that fits a given constraint (e.g., "starts with HI"). We need to validate that submitted words are real English words AND that they satisfy the round's constraint.
A CSV file containing valid words for each round is available at: https://gist.githubusercontent.com/a-lexwein/e3e6a0817c71d57c063c238f519f8b45/raw/9a06a1e2f5e4c479bb653ff39dbb65f77cd60cff/thinkOfWords.csv
The CSV format is:
id,rule,word,n_letters
1,starts with HI,histocompatibilities,20
1,starts with HI,histopathologically,19
...
Where id corresponds to the round number and rule describes the constraint.
Create a new file scripts/initDb.ts that:
- Fetches the CSV from the gist URL above
- Parses the CSV data
- Creates a SQLite table called
valid_wordswith columns:id(INTEGER) - the round numberrule(TEXT) - the constraint descriptionword(TEXT) - the valid word (lowercase)n_letters(INTEGER) - word length
- Creates an index on
(id, word)for fast lookups - Inserts all rows from the CSV
- This script should be idempotent (safe to run multiple times - drop and recreate table)
Use Val Town's SQLite: import { sqlite } from "https://esm.town/v/std/sqlite";
Add a "Setup" or "Database Initialization" section that explains:
- The game requires a word database to validate submissions
- How to run the initialization script (visit the script's endpoint or run it manually)
- Note that this only needs to be done once, or when the word list is updated
Modify the /api/validate endpoint in index.ts to:
- Accept submissions in format
{ submissions: [{ round: number, word: string }] } - For each submission, query the
valid_wordstable to check if the word exists for that round - Query:
SELECT 1 FROM valid_words WHERE id = ? AND word = ?(lowercase the word before querying) - Return
{ results: [{ round, word, isValid: boolean }] }
index.ts # Main HTTP handler with /api/validate endpoint
scripts/
initDb.ts # Database initialization script (HTTP type so it can be triggered)
README.md # Updated with setup instructions
frontend/ # (no changes needed)
- The
valid_wordstable pre-validates words against round constraints, so we only need to check if the (round, word) pair exists - Words should be compared case-insensitively (store and query in lowercase)
- The init script should be an HTTP val so it can be easily triggered via browser or curl
- Keep the init script simple - just fetch, parse, and insert