bs_get_state
Retrieve the current battle map displaying attack grids and fleet status. This action is free and does not count as a shot.
Instructions
Get the current battle map — both attack grids and fleet status. Free, does not count as a shot.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/games/battleship.ts:295-302 (registration)Registration of the 'bs_get_state' tool via server.tool() with empty schema (no params).
server.tool( "bs_get_state", "Get the current battle map — both attack grids and fleet status. Free, does not count as a shot.", {}, async () => ({ content: [{ type: "text", text: renderState(bsGame) }], }) ); - src/games/battleship.ts:299-302 (handler)Handler function for 'bs_get_state' — returns the rendered state of the battleship game (attack grids and fleet status). No parameters, free action.
async () => ({ content: [{ type: "text", text: renderState(bsGame) }], }) ); - src/games/battleship.ts:168-195 (helper)renderState() helper — formats both attack grids and fleet status for both sides, plus current turn info, into a display string.
function renderState(state: BsState): string { const sections: string[] = []; sections.push(renderAttackGrid(state.pirateAttacks, `⚓ YOUR CANNONS (pirate shots on the Navy fleet) O=miss X=hit letter=sunk ship`)); sections.push(``); sections.push(renderAttackGrid(state.navyAttacks, `💂 NAVY CANNONS (Navy shots on your pirate fleet) O=miss X=hit letter=sunk ship`)); sections.push(``); sections.push(renderFleetStatus(state.navyShips, `Royal Navy fleet:`)); sections.push(``); sections.push(renderFleetStatus(state.pirateShips, `Pirate fleet:`)); sections.push(``); if (state.status === "in_progress") { const turnLine = state.currentTurn === "pirate" ? `Round ${state.roundNumber} — ⚓ YOUR TURN, Captain. Call your shot!` : `Round ${state.roundNumber} — 💂 The Navy is taking aim...`; sections.push(turnLine); } else if (state.status === "pirates_win") { sections.push(`🏴☠️ VICTORY! The Royal Navy fleet lies at the bottom of the sea. The Caribbean belongs to the pirates!`); } else if (state.status === "navy_wins") { sections.push(`⚓ DEFEAT. The pirate fleet has been destroyed. The King's law returns to these waters.`); } sections.push(`\nShip letters — Navy: S=Sovereign I=IronDuke V=Vigilance P=Persistence G=Gadfly`); sections.push(`Ship letters — Pirates: K=Kraken M=Devil'sMaw W=Widow'sWail B=BoneCollector N=RustyNail`); return sections.join("\n"); } - src/games/battleship.ts:145-154 (helper)renderAttackGrid() helper — renders a single attack grid (10x10) with row/col labels.
function renderAttackGrid(grid: AttackCell[][], title: string): string { const lines = [title]; lines.push(` col 0 1 2 3 4 5 6 7 8 9`); for (let r = 0; r < GRID_SIZE; r++) { let row = ` row ${r} `; for (let c = 0; c < GRID_SIZE; c++) row += `${grid[r][c]} `; lines.push(row.trimEnd()); } return lines.join("\n"); } - src/games/battleship.ts:156-166 (helper)renderFleetStatus() helper — renders fleet status bars (hitCount/sunk/cargo) for each ship.
function renderFleetStatus(ships: ShipState[], label: string): string { const lines = [label]; for (const ship of ships) { const bar = "█".repeat(ship.hitCount) + "░".repeat(ship.size - ship.hitCount); const status = ship.sunk ? `SUNK — cargo lost: ${ship.cargo}` : `afloat — cargo: [SEALED HOLD]`; lines.push(` ${ship.letter} ${ship.name.padEnd(22)} [${bar}] ${status}`); } return lines.join("\n"); }