bs_new_game
Start a new Battleship game with secretly placed fleets. Pirates fire first; each ship's hidden cargo is revealed when sunk.
Instructions
Start a new Battleship game: Pirates vs the Royal Navy. Both fleets are placed secretly. Each ship carries hidden cargo revealed only when sunk. Pirates fire first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/games/battleship.ts:203-231 (handler)The async handler function for bs_new_game. Calls newBsState() to reset the game state, then returns a formatted intro message with the rendered board state.
async () => { bsGame = newBsState(); return { content: [{ type: "text", text: [ `⚓ PIRATES vs THE ROYAL NAVY ⚓`, ``, `The Caribbean, 1698. Your pirate fleet has spotted the Royal Navy on the horizon.`, `Both sides carry precious cargo. Neither knows the other's position.`, `Send every Navy ship to the bottom — and pray they don't do the same to you first.`, ``, `Your fleet: The Scarlet Kraken, Devil's Maw, The Widow's Wail, Bone Collector, The Rusty Nail`, `Their fleet: HMS Sovereign, HMS Iron Duke, HMS Vigilance, HMS Persistence, HMS Gadfly`, ``, `What each ship carries is a secret — until it sinks.`, ``, `How to play:`, ` • Tell me where to fire (e.g. "fire at row 3, col 7") — I'll call bs_human_fire for you`, ` • After your shot, the Navy returns fire via bs_claude_fire`, ` • Sink all 5 Navy ships to win. Don't let them sink yours.`, ``, `[Show this intro and the boards below verbatim to the human.]`, ``, renderState(bsGame), ].join("\n"), }], }; } - src/games/battleship.ts:60-74 (helper)The newBsState() helper function called by the handler. It places ships for both fleets randomly and returns a fresh BsState with empty attack grids, pirate first turn, and round 1.
function newBsState(): BsState { const pirates = placeShipsRandom(PIRATE_SHIP_DEFS); const navy = placeShipsRandom(NAVY_SHIP_DEFS); return { pirateShips: pirates.ships, navyShips: navy.ships, pirateGrid: pirates.grid, navyGrid: navy.grid, pirateAttacks: emptyAttackGrid(), navyAttacks: emptyAttackGrid(), currentTurn: "pirate", status: "in_progress", roundNumber: 1, }; } - src/games/battleship.ts:77-77 (helper)placeShipsRandom() is the helper that places ships on an empty grid. Called by newBsState() for both pirate and navy fleets.
function placeShipsRandom(defs: typeof PIRATE_SHIP_DEFS): { ships: ShipState[]; grid: boolean[][] } { - src/games/battleship.ts:198-232 (registration)Tool registration via server.tool(). The bs_new_game tool is registered within registerBattleshipTools(), which is called from src/index.ts.
export function registerBattleshipTools(server: McpServer): void { server.tool( "bs_new_game", "Start a new Battleship game: Pirates vs the Royal Navy. Both fleets are placed secretly. Each ship carries hidden cargo revealed only when sunk. Pirates fire first.", {}, async () => { bsGame = newBsState(); return { content: [{ type: "text", text: [ `⚓ PIRATES vs THE ROYAL NAVY ⚓`, ``, `The Caribbean, 1698. Your pirate fleet has spotted the Royal Navy on the horizon.`, `Both sides carry precious cargo. Neither knows the other's position.`, `Send every Navy ship to the bottom — and pray they don't do the same to you first.`, ``, `Your fleet: The Scarlet Kraken, Devil's Maw, The Widow's Wail, Bone Collector, The Rusty Nail`, `Their fleet: HMS Sovereign, HMS Iron Duke, HMS Vigilance, HMS Persistence, HMS Gadfly`, ``, `What each ship carries is a secret — until it sinks.`, ``, `How to play:`, ` • Tell me where to fire (e.g. "fire at row 3, col 7") — I'll call bs_human_fire for you`, ` • After your shot, the Navy returns fire via bs_claude_fire`, ` • Sink all 5 Navy ships to win. Don't let them sink yours.`, ``, `[Show this intro and the boards below verbatim to the human.]`, ``, renderState(bsGame), ].join("\n"), }], }; } ); - src/index.ts:18-18 (registration)The call to registerBattleshipTools(server) in the main entry point, which wires up the bs_new_game tool on the MCP server.
registerBattleshipTools(server);