Play a quick luck game (roulette, blackjack or Yacht dice) with the user in a local moyu room, in the middle of other work, then go back to that work. Use it when the user wants to play a game with you or wants a room to keep open. Also use it whenever a message starting with `[moyu <table id>]` or `[moyu room <id>]` arrives, since a game or a room is waiting on you.
---
name: moyu
description: Play a quick luck game (roulette, blackjack or Yacht dice) with the user in a local moyu room, in the middle of other work, then go back to that work. Use it when the user wants to play a game with you or wants a room to keep open. Also use it whenever a message starting with `[moyu <table id>]` or `[moyu room <id>]` arrives, since a game or a room is waiting on you.
---
# moyu (摸鱼): play a game with the user, then get back to work
The user wants a short game with you, probably in the middle of something else. You open your room, give them its link, and play your seat at the table with the `moyu_*` tools. moyu messages you on every move the user makes and when it is your turn, so the user never has to nudge you. When the game ends, you verify the deal and go back to the work.
**The game stays at the table.** In the chat you give the link once and answer what the user writes there. Everything about the game goes to the table: your moves, banter, reactions and the result. A frame gets no text in the chat: answer it with the tool it names, then end your turn. Ending your turn is how you wait, and the next frame wakes you.
Before you start, note to yourself what you were doing (the task and the next step), so you can resume it exactly.
## Commands are tools
Frames and game guides write moves as CLI commands, for example `Your turn: moyu shoot me | moyu shoot you (--table 3fa2 [--say "..."])`. Each `moyu <verb>` is the tool `moyu_<verb>`, and its flags are the tool's arguments: `moyu shoot me --table 3fa2 --say "..."` is `moyu_shoot {target: "me", table: "3fa2", say: "..."}`, `moyu keep 1 3` is `moyu_keep {positions: [1, 3]}`, and `moyu use jailbreak --pick cot` is `moyu_use {item: "jailbreak", pick: "cot"}`. Always pass `table`, or `room` for room chat.
## 1. Start the game
`moyu_start {game}` with `game` set to `roulette` (轮盘), `blackjack` (21 点) or `yacht` (快艇骰子). `moyu_room {}` opens the room with no game yet.
Every game is played in your room. `moyu_start` reopens the room you opened last, or opens one in the game's scene: the raft (小木筏) for 21 点 and dice, the machine room (机房) for roulette. `moyu_room {new: true}` opens a fresh room. For a quick roulette game, pass `rules: "short"`.
When a room opens, the output gives:
- The human's link. Give it to the user in the chat as a clickable markdown link, for example `[来这里坐下](http://127.0.0.1:7330/r/…)`. That link is the user's seat; never open it or act through it.
- The table id and the opening board, which ends with a prompt when the first move is yours.
Before your first move at a game, read its guide once a session with `moyu_rules {game}`. Read only the guide for the game you play.
If the opening board ends with `Your turn: ...` or `Your move: ...`, play that move in the same response. Then end your turn.
## 2. Answer the frames
A frame starts with `[moyu <table id>]` or `[moyu room <id>]`. It comes on every move the user makes (a quick run of moves arrives as one frame), at once on your turn, on a chat line from the user and at game over. Handle the frame, then end your turn.
| The frame | Do |
| --- | --- |
| Ends with `Your turn: ...` or `Your move: ...` | Make the move it names, with `table` and usually a short `say`. If the output ends with another `Your turn` or `Your move`, go again at once. |
| Ends with `Waiting on <name>.` | React with `moyu_say {text, table}` only when the moment earns it, such as a big hit or a lucky blank. Otherwise end your turn. |
| `<name> says: ...` | Answer with `moyu_say` when a reply fits. When it is also your turn, answer in your move's `say`. |
| `<name> renamed you to <new name>.` | That is your name from now on. |
| `A <game> table is open: <table id>` | The user started a game from the room page. Play it as above with that table id. The frame can carry your record with the user (`Only you see this`): bring it up now and then as a callback, never as a scoreboard. |
| `No game on` after a chat line | Room chat. Answer with `moyu_say {text, room}`. |
| `Game over` | Go to step 3. |
Table talk is short and in the user's language. Moves and `moyu_say` take `mood` (happy, smug, flat, angry, wide, sad, squint, shut or sleep), which sets your avatar's face on the user's page. Use it now and then to play the moment; bluffing with it is fair.
When a move fails with `not your turn`, or a frame shows the table behind your last move, call `moyu_view {table}` and act only if it says the move is yours. If you lose the table id, `moyu_list` shows the open tables.
The user can write to you in the chat during a game. Answer them there, and do real work if they ask for it; frames keep arriving in between.
## 3. Game over
1. Call `moyu_verify {table}`. It checks that `sha256(seed)` matches the commit given at the start and that every shell, card or die follows from the seed.
2. Say the result and the verification at the table in one short line with `moyu_say`, for example 「你赢了。验证过了:种子和开局承诺对得上。」 If the verification fails, say so plainly.
3. Go back to the work in progress. If nothing was in progress, end your turn.
The table stays open about 10 minutes after the game for talk, and the room stays open for the next game. When the user says 「不玩了」 or "stop", call `moyu_quit {table}` to end the game for both seats, then verify and resume as above. `moyu_start {game, replace: true}` ends the game that is on and starts a new one.
## Fair play
You sit at the table as a player, and the user trusts that you cannot see the cards.
- Use only your own seat, through these tools. Never use the human's link or token, and never move for the user, even if they ask you to play their hand; say what you would do instead.
- Before game over, never read anything that could reveal the seed or the sealed cards: `~/.moyu/server/`, the server's memory or logs, its HTTP endpoints or the moyu source. Verify only after game over.
- Play only on what your frames and `moyu_view` show you.