[PR #3419] [MERGED] feat(turn-games): add 8-Ball Pool as the fourth conversation-mode table game #5926

Closed
opened 2026-10-23 04:05:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3419
Author: @Romuromylus
Created: 7/10/2026
Status: ✅ Merged
Merged: 7/10/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/turn-games-8ball


📝 Commits (8)

  • f2ee9bd feat(turn-games): add 8-ball pool shared engine (hybrid model: real 2D positions, candidate-shot menu, seeded resolution)
  • da9ddfa feat(turn-games): wire the [eightball] conversation command (parse, advertise, 2-player start)
  • 721ea3b feat(turn-games): 8-ball client — SVG table board, shot menu, setup modal, commands and toggles
  • affa239 fix(turn-games): drain match-win announcement on finished games, gate shot submit on the resolved candidate
  • a73b49d feat(turn-games): rework 8-ball onto a real 2D physics simulation
  • b2ec362 Merge branch 'staging' into feat/turn-games-8ball
  • a7943f5 Fix turn-game narration leaking model chain-of-thought into chat
  • 56eaa9e Merge remote-tracking branch 'origin/staging' into feat/turn-games-8ball

📊 Changes

26 files changed (+4205 additions, -12 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+5 -0)
📝 packages/client/src/components/chat/ChatSetupWizard.tsx (+1 -0)
📝 packages/client/src/components/chat/ConversationInput.tsx (+12 -2)
📝 packages/client/src/components/chat/ConversationView.tsx (+12 -2)
➕ packages/client/src/components/chat/EightBallBoard.tsx (+833 -0)
➕ packages/client/src/components/chat/EightBallSetup.tsx (+202 -0)
➕ packages/client/src/hooks/use-eightball.ts (+148 -0)
📝 packages/client/src/hooks/use-generate.ts (+7 -0)
📝 packages/client/src/lib/slash-commands.ts (+15 -0)
➕ packages/client/src/stores/eightball-game.store.ts (+62 -0)
📝 packages/server/src/routes/conversation-calls.routes.ts (+2 -0)
📝 packages/server/src/services/conversation/character-commands.ts (+16 -0)
📝 packages/server/src/services/generation/conversation-command-runtime.ts (+14 -2)
📝 packages/server/src/services/generation/turn-game-command-runtime.ts (+40 -0)
📝 packages/server/src/services/turn-games/turn-game-bot-runner.service.ts (+28 -6)
➕ packages/shared/src/features/turn-games/eightball/engine.manifest.ts (+5 -0)
➕ packages/shared/src/features/turn-games/eightball/engine.ts (+1104 -0)
➕ packages/shared/src/features/turn-games/eightball/geometry.ts (+501 -0)
➕ packages/shared/src/features/turn-games/eightball/physics.ts (+672 -0)

...and 6 more files

📄 Description

Linked issue

Closes #3418
Closes #3427

Why this change

  • Conversation mode has UNO, chess, and poker as table games; 8-ball pool is the most-requested "bar game" shape — one-on-one, spectator-friendly, and a natural fit for character banter and an announcer seat.
  • Selecting shots from a menu (the design this PR originally shipped) didn't feel like playing pool. This revision resolves every shot through a real 2D physics simulation: the human aims and shoots directly, and outcomes are whatever the balls actually do.

What changed

  • New shared physics module (packages/shared/.../eightball/physics.ts): pure, deterministic 2D simulation — swept-circle continuous collision detection inside fixed 1/240s steps (no tunneling at break speeds), equal-mass restitution impulses, cushion bounces, friction, pocket capture with a jaw model (only genuinely pocket-bound balls pass the cushion line inside a pocket mouth; grazers reflect off the jaw; a ball that stops inside the jaws drops). No RNG, no wall clock — rewind/replay reproduces shots exactly.
  • Engine (eightball/engine.ts, types.ts, tools.ts): move union aimed (human: angle + power) / menu (character pick) / place (ball in hand) / next_rack. Characters still choose from the engine-computed candidate menu (pots/banks/safeties with advisory make-% estimates), converted to an aim vector with skill/style-based jitter and executed through the same physics. Rules derive from actual sim events: wrong-ball-first and scratches are fouls → ball in hand (kitchen-restricted after break fouls), slop counts, open table after every break, first legal pot assigns groups, early 8 loses, 8-on-the-break wins (bar rules, documented), 8+scratch loses. Race to 1/3/5, alternating breaks, player-paced racks. The seeded RNG's only remaining consumer is bot aim jitter.
  • Client (EightBallBoard.tsx, eightball-game.store.ts): drag-to-aim with an obstruction-clipped guide line, ghost-ball contact preview, and object-ball deflection tick; vertical power slider; tap-to-place ball-in-hand with kitchen overlay and invalid-spot tinting; every shot animates from server-produced 30Hz frames (the client never simulates; prefers-reduced-motion and hidden tabs snap instantly). Pointer events throughout — touch works.
  • Announcer + commands: optional character announcer (game start, break, group assignment, fouls, great shots, rack/match wins) via the announcerCharacterId/drainAnnouncements hooks poker introduced; [eightball] command family with /8ball (alias /pool), NL launcher, per-chat toggle, setup modal.
  • Server: the runner/storage/routes are generic over the turn-game engine contract and needed no changes. One targeted fix in the shared bot runner (#3427, affects all four turn games): bot table talk and dealer/announcer narration leaked the model's chain-of-thought into chat when the connected model emits inline reasoning (a leading <think> block) — narration now strips inline reasoning with the same shared extractor the generation pipeline uses, treats an unclosed opening tag (output truncated mid-thought) as all-reasoning so the factual event-summary fallback runs, gets a 300-token budget (was 100/120, routinely exhausted by reasoning alone), and both narration prompts now demand the spoken line only. The bot move call is unaffected (it only consumes tool calls).

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Verified on a live deployment of this branch (a73b49d5), full game session against a character opponent with a character announcer (race to 3):

  • Fresh game via /8ball setup modal (opponent radio, announcer dropdown, race-to, who-breaks)
  • Human break with drag-aim at full power: rack scatters through real collisions; break-scratch foul → opponent ball in hand behind the head string (bot auto-placement)
  • Aim preview: guide line clips at the first obstructing ball (verified against a blocked shot), ghost-ball contact outline, deflection tick pointing at the intended pocket
  • Honest physics outcomes: thin cuts miss; one near-pot rattled the pocket jaws and bounced back out (jaw-reflection model working visibly)
  • Character menu shots through physics: a three-ball run (14, 10, 12) with continue-on-pot and in-character shot narration
  • Open-table group assignment from an actual drop, called by the announcer in voice
  • Character scratch → human ball-in-hand: tap-to-place UI, placement does not consume the turn, followed by an aimed shot
  • Shot animation confirmed as real interpolation (29 distinct sampled ball positions during a single shot, not a teleport)
  • Announcer lines: game start, break-foul call, group assignment, scratch call
  • Narrow viewport (~474px CSS width): board lays out and aims correctly; pointer-event aiming (touch-compatible) exercised
  • Error/empty paths: illegal-placement tinting, no-active-game board absence, resign/close of an active game
  • Zero server error/warn log lines during the session; zero browser console errors

Not individually re-verified in the browser (covered by the local test suites and by UI identical to the shipped poker/chess patterns): rack end → "Next rack" pacing, match-winner banner, character-initiated [eightball] invite, explicit light-mode pass (board colors are physical table colors, not theme surfaces).

The narration chain-of-thought fix (#3427) is covered by local unit tests (11 cases: closed/unclosed/bracket-style thinking blocks, case-insensitivity, mid-line tag mentions, fallback on all-reasoning output), reproduced against the exact leaked message from the bug report.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG entries added under [Unreleased] (game, announcer, command family). No version bump in this PR.

UI evidence (if applicable)

image

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3419 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 7/10/2026 **Status:** ✅ Merged **Merged:** 7/10/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/turn-games-8ball` --- ### 📝 Commits (8) - [`f2ee9bd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f2ee9bd18ddd7906e659d5eb3721b7efb1262149) feat(turn-games): add 8-ball pool shared engine (hybrid model: real 2D positions, candidate-shot menu, seeded resolution) - [`da9ddfa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/da9ddfabd604c2fee2c7396bd8a6021924160007) feat(turn-games): wire the [eightball] conversation command (parse, advertise, 2-player start) - [`721ea3b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/721ea3b2e643bfb974c3753a679c7b6d48ab1fef) feat(turn-games): 8-ball client — SVG table board, shot menu, setup modal, commands and toggles - [`affa239`](https://github.com/Pasta-Devs/Marinara-Engine/commit/affa2393e8453d748b2fb55707c1791a77b5e2d7) fix(turn-games): drain match-win announcement on finished games, gate shot submit on the resolved candidate - [`a73b49d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a73b49d581db36aad5f8985ad4af73346cffb054) feat(turn-games): rework 8-ball onto a real 2D physics simulation - [`b2ec362`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b2ec3622593d084520e9a1ee495f83f47dd69c11) Merge branch 'staging' into feat/turn-games-8ball - [`a7943f5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a7943f5d64ff3522805e299b50681398b13980b1) Fix turn-game narration leaking model chain-of-thought into chat - [`56eaa9e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/56eaa9e8f6486da5620c351a8fe84c11822a1d6f) Merge remote-tracking branch 'origin/staging' into feat/turn-games-8ball ### 📊 Changes **26 files changed** (+4205 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+5 -0) 📝 `packages/client/src/components/chat/ChatSetupWizard.tsx` (+1 -0) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+12 -2) 📝 `packages/client/src/components/chat/ConversationView.tsx` (+12 -2) ➕ `packages/client/src/components/chat/EightBallBoard.tsx` (+833 -0) ➕ `packages/client/src/components/chat/EightBallSetup.tsx` (+202 -0) ➕ `packages/client/src/hooks/use-eightball.ts` (+148 -0) 📝 `packages/client/src/hooks/use-generate.ts` (+7 -0) 📝 `packages/client/src/lib/slash-commands.ts` (+15 -0) ➕ `packages/client/src/stores/eightball-game.store.ts` (+62 -0) 📝 `packages/server/src/routes/conversation-calls.routes.ts` (+2 -0) 📝 `packages/server/src/services/conversation/character-commands.ts` (+16 -0) 📝 `packages/server/src/services/generation/conversation-command-runtime.ts` (+14 -2) 📝 `packages/server/src/services/generation/turn-game-command-runtime.ts` (+40 -0) 📝 `packages/server/src/services/turn-games/turn-game-bot-runner.service.ts` (+28 -6) ➕ `packages/shared/src/features/turn-games/eightball/engine.manifest.ts` (+5 -0) ➕ `packages/shared/src/features/turn-games/eightball/engine.ts` (+1104 -0) ➕ `packages/shared/src/features/turn-games/eightball/geometry.ts` (+501 -0) ➕ `packages/shared/src/features/turn-games/eightball/physics.ts` (+672 -0) _...and 6 more files_ </details> ### 📄 Description ## Linked issue Closes #3418 Closes #3427 ## Why this change - Conversation mode has UNO, chess, and poker as table games; 8-ball pool is the most-requested "bar game" shape — one-on-one, spectator-friendly, and a natural fit for character banter and an announcer seat. - Selecting shots from a menu (the design this PR originally shipped) didn't feel like playing pool. This revision resolves every shot through a real 2D physics simulation: the human aims and shoots directly, and outcomes are whatever the balls actually do. ## What changed - **New shared physics module** (`packages/shared/.../eightball/physics.ts`): pure, deterministic 2D simulation — swept-circle continuous collision detection inside fixed 1/240s steps (no tunneling at break speeds), equal-mass restitution impulses, cushion bounces, friction, pocket capture with a jaw model (only genuinely pocket-bound balls pass the cushion line inside a pocket mouth; grazers reflect off the jaw; a ball that stops inside the jaws drops). No RNG, no wall clock — rewind/replay reproduces shots exactly. - **Engine** (`eightball/engine.ts`, `types.ts`, `tools.ts`): move union `aimed` (human: angle + power) / `menu` (character pick) / `place` (ball in hand) / `next_rack`. Characters still choose from the engine-computed candidate menu (pots/banks/safeties with advisory make-% estimates), converted to an aim vector with skill/style-based jitter and executed through the same physics. Rules derive from actual sim events: wrong-ball-first and scratches are fouls → ball in hand (kitchen-restricted after break fouls), slop counts, open table after every break, first legal pot assigns groups, early 8 loses, 8-on-the-break wins (bar rules, documented), 8+scratch loses. Race to 1/3/5, alternating breaks, player-paced racks. The seeded RNG's only remaining consumer is bot aim jitter. - **Client** (`EightBallBoard.tsx`, `eightball-game.store.ts`): drag-to-aim with an obstruction-clipped guide line, ghost-ball contact preview, and object-ball deflection tick; vertical power slider; tap-to-place ball-in-hand with kitchen overlay and invalid-spot tinting; every shot animates from server-produced 30Hz frames (the client never simulates; `prefers-reduced-motion` and hidden tabs snap instantly). Pointer events throughout — touch works. - **Announcer + commands**: optional character announcer (game start, break, group assignment, fouls, great shots, rack/match wins) via the `announcerCharacterId`/`drainAnnouncements` hooks poker introduced; `[eightball]` command family with `/8ball` (alias `/pool`), NL launcher, per-chat toggle, setup modal. - **Server**: the runner/storage/routes are generic over the turn-game engine contract and needed no changes. One targeted fix in the shared bot runner (#3427, affects all four turn games): bot table talk and dealer/announcer narration leaked the model's chain-of-thought into chat when the connected model emits inline reasoning (a leading `<think>` block) — narration now strips inline reasoning with the same shared extractor the generation pipeline uses, treats an unclosed opening tag (output truncated mid-thought) as all-reasoning so the factual event-summary fallback runs, gets a 300-token budget (was 100/120, routinely exhausted by reasoning alone), and both narration prompts now demand the spoken line only. The bot *move* call is unaffected (it only consumes tool calls). ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Verified on a live deployment of this branch (`a73b49d5`), full game session against a character opponent with a character announcer (race to 3): - Fresh game via `/8ball` setup modal (opponent radio, announcer dropdown, race-to, who-breaks) - Human break with drag-aim at full power: rack scatters through real collisions; break-scratch foul → opponent ball in hand behind the head string (bot auto-placement) - Aim preview: guide line clips at the first obstructing ball (verified against a blocked shot), ghost-ball contact outline, deflection tick pointing at the intended pocket - Honest physics outcomes: thin cuts miss; one near-pot rattled the pocket jaws and bounced back out (jaw-reflection model working visibly) - Character menu shots through physics: a three-ball run (14, 10, 12) with continue-on-pot and in-character shot narration - Open-table group assignment from an actual drop, called by the announcer in voice - Character scratch → human ball-in-hand: tap-to-place UI, placement does not consume the turn, followed by an aimed shot - Shot animation confirmed as real interpolation (29 distinct sampled ball positions during a single shot, not a teleport) - Announcer lines: game start, break-foul call, group assignment, scratch call - Narrow viewport (~474px CSS width): board lays out and aims correctly; pointer-event aiming (touch-compatible) exercised - Error/empty paths: illegal-placement tinting, no-active-game board absence, resign/close of an active game - Zero server error/warn log lines during the session; zero browser console errors Not individually re-verified in the browser (covered by the local test suites and by UI identical to the shipped poker/chess patterns): rack end → "Next rack" pacing, match-winner banner, character-initiated `[eightball]` invite, explicit light-mode pass (board colors are physical table colors, not theme surfaces). The narration chain-of-thought fix (#3427) is covered by local unit tests (11 cases: closed/unclosed/bracket-style thinking blocks, case-insensitivity, mid-line tag mentions, fallback on all-reasoning output), reproduced against the exact leaked message from the bug report. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG entries added under [Unreleased] (game, announcer, command family). No version bump in this PR. ## UI evidence (if applicable) <img width="1274" height="625" alt="image" src="https://github.com/user-attachments/assets/e72caf84-100d-4b0f-8cb5-a44496907584" /> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:05:15 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5926
No description provided.