# Playtesting with an AI player

A person cannot test a game on the days nobody is free, and the bots (`autoplay`, `fuzz`) only prove the game *can* be finished — they know the
ids. A language model reading the game as text is a third kind of tester: it has to *work out* what to do from what the screen says, the way a first-time
player does. It gets stuck where players get stuck (a clue nobody is pointed at, a door that looks like scenery, a puzzle whose rules are in the wrong
place), and it says so in words. It is **not** a substitute for people — it has no eyes, no ears and no patience to lose — but it is free, repeatable, available
at 3 a.m., and it reads every line you wrote.

Nothing leaves the computer: the game runs locally, headless; the only thing sent anywhere is what *you* paste to the AI you are using. No API key is involved.

## What the tester sees

`tools/text_play.gd` boots the **real** game UI (the same one the walkthrough and autoplay bots drive) and talks through standard input and output.
A room is the list of things that can be clicked; a conversation is its numbered replies; a puzzle is its own on-screen controls, numbered. A board that is
*drawn* (positions, a maze) describes itself in words through `text_state()` on the puzzle (`puzzles/puzzle_base.gd`). Nothing is hidden behind a guess and
nothing extra is revealed: the tester gets what a player's screen would give, plus the ids in `[brackets]` it needs to type.

```
== Pennyfold Savings ==
You can see:
  [door_square] Out to the square — a way through
  [tilly] Tilly Brandt — someone to talk to
  [plaque] The founders' plaque — look closer
  …
> click plaque
"PENNYFOLD SAVINGS BANK — ESTABLISHED MDCCCLXXXVII — …"
```

| Command | What it does |
|---|---|
| `look` | the room again |
| `click <thing>` | the obvious thing: go through a door, look closer, pick it up, talk to them (an id or what it is called) |
| `choose <n or words>` | a reply in a conversation |
| `use <item> on <thing>` · `combine <item> with <item>` | items |
| `inventory` · `journal` · `tasks` · `clues` · `suspects` · `mail` · `phone` · `map` | the panels |
| `call <contact>` · `answer` · `decline` · `reply <text id>` · `read <mail id>` · `travel <place>` | the phone, the inbox, the map |
| `hint` · `hint more` | the hint system (it counts, exactly as for a player) |
| `accuse <suspect> means=<clue> motive=<clue> opportunity=<clue>` | the finale, once the case can be made |
| `puzzle` · `press <n>` · `type <n> <text>` · `act …` · `leave` · `skip` | inside a puzzle |
| `wait <seconds>` · `note <words>` · `help` · `quit` | time, a remark for the report, the list above |

The game's clock stops while the tester thinks, so a slow reader never loses a phone call. With `--dev` (never given to a tester) there are two shortcuts:
`debug solve` and `debug goto <room>`, used by the automated replays.

## Running one

```bash
make text-play GAME=samples/pennyfold                                    # you, at a terminal
python3 samples/pennyfold/tools/llm_session.py start --name tester1      # an AI agent: a session in the background, one command per call
python3 samples/pennyfold/tools/llm_session.py say <session> "click the bank"      # <session> is the name `start` printed
python3 samples/pennyfold/tools/llm_session.py stop <session>             # the summary; the transcript is in build/llm/<session>/transcript.jsonl
```

`start` prints the session name and the opening. `say <session> "<command>"` is one round trip. (`last` means the newest session, and is refused when more than one is running: testers that run at the same time must name theirs, or they play each other's game.) Every session writes `transcript.jsonl` (each command,
the full answer and the state after it), `summary.json` and `summary.txt` under `<game>/build/llm/<session>/`. A session ends on `stop`, on the game's ending,
after 30 idle minutes, or at `--max-turns` (default 400 — a tester that is still wandering by then is a finding).

## The brief to give the tester

Paste this to an AI agent that can run shell commands (a Claude Code subagent, a chat with a terminal tool…), changing the game folder. **It must not read the
game's files** — `game/*.json` holds the answers; a tester that reads them is testing nothing.

> You are a playtester for a detective adventure game. You play it only by typing commands into a text front end, exactly as a person who had never seen the
> game would. Do **not** read any file inside the game folder (`game/`, `addons/`, the generator…): that would spoil the case and invalidate the test. Use only these shell commands:
>
> `python3 <GAME>/tools/llm_session.py start --name <your name>` — starts the game and prints the opening and the session name.
> `python3 <GAME>/tools/llm_session.py say <session> "<command>"` — sends one command and prints the answer. Use the session name `start` printed, every time. Start with `help`.
> `python3 <GAME>/tools/llm_session.py stop <session>` — when you finish or give up.
>
> In a conversation, `choose` with a few of the reply's words rather than its number: numbers change as replies are used up. Your goal is to solve the case: work out who did it and how, why and when, collect the clues, and make the accusation. Think aloud as you go, briefly.
> Whenever something confuses you — an unclear thing to click, a rule you could not find, a puzzle you could not tell how to start, a place you did not know you could
> go, a reply that did not match what you meant — send `note <what confused you and what you expected>`; notes are the most valuable thing you produce, and
> so are things you liked. Ask for a hint only when you are truly stuck, and say why in a note first. Give up (and `stop`) after about 250 commands.
> Finish by writing three sentences: how it felt, the worst moment, the best moment.

Variations worth running as separate testers (each is a new session): **the methodical one** ("write down every clue before moving on"), **the impatient one**
("take the shortest route you can see; never re-read; use a hint as soon as you are unsure"), **the lateral one** ("try what the game did not ask of you:
use items on people, go back to rooms, talk to everyone twice"), and **the other difficulty** (`--difficulty=senior`: no hints).

## Reading what they found

```bash
make llm-report GAME=samples/pennyfold OUT=build/llm_report.md
```

The report combines the sessions: how many won, turns to win, where testers **stalled** (15 or more turns with nothing new found — by room), which commands the
game refused or did not understand (by room), which puzzles were solved, and every `note`, with the room and the turn. Read it in this order:

1. **Stalls and unfinished sessions.** A room where three testers stall is a clue that is not signposted or a door that does not look like one. Add a hint
   (`hints.json`), change the label, or move the clue — then run the testers again.
2. **Refused commands.** `You can't see anything like …` after a tester names a thing the screen did not list means the *description* promised something the room does not have.
3. **Notes.** Each is a sentence from someone who had never seen the game. Group them; the same note from two testers is a bug in the writing.
4. **The win itself.** A tester that wins without asking for a hint, in about as many turns as the walkthrough, is a good sign for an average player; one that needs
   the hint at the same place every time has found the spot where the real playtest's hint button will be pressed.

## What it cannot tell you

- Whether it is *beautiful* — there are no pictures, sounds or voices in the text.
- Whether a puzzle is *fun*: a model solves a logic grid by reasoning and an arcade puzzle (timing, dexterity) not at all.
- Puzzle types whose board is drawn but has not yet described itself in words show up as "(unlabelled)" or an empty control list: that is a finding about the game's
  accessibility as much as about the tester (`make puzzle-a11y` lists them).
- How *people* feel: models are patient, literal and brave about leaving things unread. Use them to find the dead ends cheaply, so the weekend's human test
  (`docs/WEEKEND_TEST_PLAN.md`) is spent on feeling.

## Keeping it honest

`make text-test` (and the `text` step of every game's `tools/check.sh`) replays the recorded walkthroughs as typed commands and runs the typed routes in
`game/walkthroughs/*.txt`, so a change that breaks the text front end fails the build like any other. The generator that makes the sample games writes a typed route
beside each walkthrough (`samples/gen/pennyfold/textroute.mjs`); a line may end in `  ## words` — the answer to that command must contain them.
