# pi-tic-tac-toe

Play a quick game of tic tac toe against the LLM inside [Pi](https://github.com/earendil-works/pi).

`pi-tic-tac-toe` adds a persistent TUI overlay opened with `/tic-tac-toe`. You play `X`, the LLM plays `O`, and the game stays in your Pi session so you can close the overlay and resume later.

## Features

- Centered terminal overlay, built with Pi TUI
- Human vs LLM gameplay
- Arrow-key and number-key input
- Session persistence across Pi reloads/resumes
- Validated saved state and legal move checking
- TypeScript source, no build step required
- Manual npm publish workflow included

## Install

```bash
pi install npm:pi-tic-tac-toe
```

Or add it to `~/.pi/agent/settings.json`:

```json
{
  "packages": ["npm:pi-tic-tac-toe"]
}
```

## Usage

Start or resume a game:

```text
/tic-tac-toe
```

Start a fresh game:

```text
/tic-tac-toe new
```

## Controls

| Key | Action |
| --- | --- |
| Arrow keys | Move cursor |
| `1`-`9` | Jump to a square |
| Enter | Place `X` |
| `n` | New game |
| `q` | Close overlay |

The overlay is TUI-only. It will not open in Pi print, JSON, or RPC modes.

## How It Works

After you place `X`, the extension asks the LLM to play `O` by calling:

```text
make_tic_tac_toe_move
```

The extension validates every move, so the LLM cannot move out of turn, overwrite a square, or continue after the game is over.

## Development

```bash
npm install
npm test
npm run check
```

Try the extension locally:

```bash
pi -e ./extensions/index.ts
```

Then run:

```text
/tic-tac-toe
```

## Package Notes

Pi loads TypeScript extensions directly, so this package publishes the source `.ts` files. Pi core packages are declared as peer dependencies to avoid bundling duplicate Pi runtime packages.

## License

MIT
