diff --git a/challenges/vibe-coding-mad-libs/README.md b/challenges/vibe-coding-mad-libs/README.md index b915591..980da82 100644 --- a/challenges/vibe-coding-mad-libs/README.md +++ b/challenges/vibe-coding-mad-libs/README.md @@ -2,14 +2,16 @@ A 10-minute terminal challenge. The participant fills four Mad Libs blanks, Theme, Subject, Audience, and Style, by inventing answers or rolling physical -dice against [`dice-sheet.md`](dice-sheet.md). Pi builds a self-contained -`index.html` from the sentence, shows it in Chrome beside the station, and -then makes one change the participant asks for. +dice and looking each roll up under Roll dice in the form, which shows the +tables in [`dice-sheet.md`](dice-sheet.md). Pi builds a self-contained +`index.html` from the sentence, offers to show it in Chrome beside the +station, and then makes one change the participant asks for. | File | Role | | --- | --- | -| `mad-libs.mjs` | Pi extension: the four-blank form and `/mad-libs` | +| `mad-libs.mjs` | Pi extension: the four-blank form, its Roll dice tables, and `/mad-libs` | | `prompt.mjs` | Assembles and checks the sentence | +| `dice.mjs` | Parses `dice-sheet.md` into the Roll dice tables | | `preview.mjs` | Serves `index.html` on `http://127.0.0.1:4321/` with live reload | | `install` | Installs the Pi packages the extension imports | | `setup`, `cleanup` | Copy the dice sheet and start the preview; stop it | @@ -20,7 +22,7 @@ Install Pi and the adapter at the versions boothstrap pins, as in boothstrap's authoring guide, then, from this repo's root: ```sh -challenge="$PWD/vibe-coding-mad-libs" +challenge="$PWD/challenges/vibe-coding-mad-libs" "$challenge/install" mkdir -p tmp/mad-libs && cd tmp/mad-libs "$challenge/setup" diff --git a/challenges/vibe-coding-mad-libs/challenge.json b/challenges/vibe-coding-mad-libs/challenge.json index 55df3bc..f245878 100644 --- a/challenges/vibe-coding-mad-libs/challenge.json +++ b/challenges/vibe-coding-mad-libs/challenge.json @@ -16,7 +16,7 @@ { "id": "fill-prompt", "title": "Fill in your prompt", - "hint": "Fill the four blanks. Invent answers, or roll dice and ask Pi to show dice-sheet.md.", + "hint": "Fill the four blanks. Invent answers, or roll dice and look them up under Roll dice in the form.", "done_when": "The participant sent a prompt naming a kind of app, a subject, an audience, and a style, with no blank left unfilled." }, { diff --git a/challenges/vibe-coding-mad-libs/dice.mjs b/challenges/vibe-coding-mad-libs/dice.mjs new file mode 100644 index 0000000..cf7ec01 --- /dev/null +++ b/challenges/vibe-coding-mad-libs/dice.mjs @@ -0,0 +1,49 @@ +// The optional dice tables, parsed from dice-sheet.md. dice-sheet.md is the +// one source: the form shows these tables, and setup copies the file into the +// workspace. + +import { readFileSync } from 'node:fs' + +import { FIELDS } from './prompt.mjs' + +const DICE_SHEET = new URL('./dice-sheet.md', import.meta.url) + +const TABLE_HEADING = /^## (\w+) \(d(\d+)\)$/ +const TABLE_ROW = /^\| (\d+) \| (.+?) \|$/ + +/** + * Parses a dice sheet's `##