# Battleship

A complete, self-contained Battleship game for the browser — no build step, no dependencies, no external assets. Just open `index.html` and play.

## Files

| File | Purpose |
|---|---|
| `index.html` | Markup: boards, ship tray, controls, end screen |
| `style.css` | Responsive naval theme, animations (splash, explosion, sinking, confetti) |
| `audio.js` | Synthesized sound engine (Web Audio API — zero audio files) |
| `ai.js` | Computer opponent: hunt/target strategy |
| `game.js` | Game state, ship placement, battle loop, UI |

## How to play

1. **Deploy** — drag a ship from the fleet tray onto your waters, or tap a ship and then tap a cell.
   - **Rotate:** double-tap a ship, the Rotate button, or press `R`.
   - **Random** auto-deploys the fleet; **Clear** starts over.
2. **Battle** — tap any cell in the enemy waters to fire. Hits, misses and sunk ships are marked; the enemy fires back between your shots.
3. **Win** — sink all five enemy ships before your fleet goes under. The end screen shows shots, hits and accuracy, with **Play again** to restart.

Ships: Carrier (5), Battleship (4), Cruiser (3), Submarine (3), Destroyer (2) on a 10×10 grid.

## Features

- Works with **mouse and touch** (pointer events; drag with a finger, ghost ship floats above it)
- **Hunt/target AI**: checkerboard parity hunting, then orthogonal targeting with line-extension priority once hits align; unresolved hits are kept when a sink reveals another wounded ship (~48 shots to win on average)
- Animated feedback: splash rings, explosion flash + sparks, staggered sinking, board shake, last-shot pulse, win confetti
- Sound effects and a battle horn generated live with the Web Audio API (mute button in the header, preference remembered)
- Turn indicator, fleet trackers for both sides, invalid-shot wiggles, hover previews during placement
- Responsive: side-by-side boards on desktop, stacked with enemy waters on top on phones; respects `prefers-reduced-motion`

## Notes

- All game logic runs locally; sound starts after the first tap (browser autoplay policy).
- The AI code is plain ES6 with no DOM dependencies, so it can be unit-tested head-lessly in Node.
