# Battleship

**Battleship** is a shared-screen naval duel for RCWeb. One browser becomes the war room: a single unified ocean chart divided into a sector for every captain. Each phone becomes a private bridge where that captain hides a fleet and calls the shots. The chart shows only what the shells have found, so the ships stay secret until they are hit.

![icon](pwa-512x512.png "Battleship Display Icon")

## The game

The display draws **one ocean**, not one board per player. Every captain owns a sector of that ocean and the whole chart shares a single coordinate system, so a shot called at `Q12` means the same square on the big screen and on every phone in the room.

Battleship supports **1 to 6 human captains**. A solo player gets an **AI captain** automatically, and AI captains can be added or removed from any phone to fill the room up to six fleets.

- **Two captains** fight a classic duel on **10x10** sectors with five ships: Carrier (5), Battleship (4), Cruiser (3), Submarine (3) and Destroyer (2).
- **Three to six captains** fight a free-for-all on **8x8** sectors with four ships: Battleship (4), Cruiser (3), Submarine (3) and Destroyer (2).

Play runs in three phases. In **placement** every captain hides a fleet at the same time on their own phone, and the chart shows only who is ready. In **battle** captains take turns: pick a rival fleet, tap a square, then fire. **A hit earns another shot**, a miss passes the guns to the next captain. When every ship in a sector is sunk that fleet is out, and the **last fleet afloat wins**.

A turn clock keeps the game moving. If a captain runs out of time a shot is fired for them, and a captain who drops off the network has their turn skipped until they return.

## How to play

Open `/battleship/` on the shared screen. Players scan the QR code to open `/battleship-c/` on their phones in the same room, and pick a captain name.

1. Any phone presses **Start battle**. With only one human captain an AI opponent joins automatically.
2. Every phone gets a randomly hidden fleet. Tap a ship, tap a square to move it, **Rotate** to turn it, **Shuffle** for a fresh layout, then press **Ready**.
3. On your turn, choose a rival fleet from the tabs, tap a square on their sector, and press **Fire**.

While you line up a shot the crosshair appears live on the shared screen, so the room can see where the guns are pointing before the shell lands. Your phone buzzes when your own waters are hit.

## Powered by RCWeb

Battleship uses RCWeb's room-based WebSocket layer to split one game across many screens. The display and every phone join the same RCWeb room using the `rc` values injected by the Java server, and the display publishes a QR code with the room already selected.

The display owns the entire game: it deals sectors, validates fleet layouts, resolves every shot, tracks sunk ships, runs the turn order and turn clock, plays the AI captains, and decides when a battle is over. Ship positions never leave the display except in the private snapshot sent to that ship's owner, which is what makes hidden information work across a room full of devices.

Phones send intents through `comms.js` - join, place, ready, aim, fire, rematch - and receive a tailored snapshot containing their own fleet, their own damage, and the public shot grid of every rival. The AI captains run on the display with a simple hunt-and-target search: random parity fire until something is hit, then work the neighbouring squares and follow the line of a wounded ship until it sinks.

## Screenshots

![Live crosshair while the captain aims](screenshot01.png)

![Battle chart after several exchanged salvos](screenshot02.png)

![Later battle with additional hits and misses](screenshot03.png)
