# Battleship

Classic Battleship in the browser: you against the computer on 10x10 grids. Plain HTML, CSS and JavaScript with no build step and no dependencies.

## Run it

Open `index.html` in any modern browser (double-click works), or serve the folder:

```
python3 -m http.server 8000   # then visit http://localhost:8000
```

## How to play

1. **Place your fleet** (Carrier 5, Battleship 4, Cruiser 3, Submarine 3, Destroyer 2).
   - Drag a ship from the dock onto the grid (mouse or touch). Drag placed ships to move them; drop one off the grid to send it back to the dock.
   - Or select a ship and click/tap a square. On desktop a green/red preview follows the mouse.
   - Rotate with the **Rotate** button, the `R` key, right-click or a second finger while dragging. Tapping a placed ship rotates it in place.
   - **Randomize** and **Clear** are available too. Pick the computer skill, then **Start battle**.
2. **Fight.** Tap or click a square on the enemy grid to fire (keyboard: arrow keys and Enter/Space). Turns alternate; a hit does not grant an extra shot.
3. First to sink all five enemy ships wins. The end screen shows stats; **Play again** restarts, **View boards** lets you inspect the final position (on a loss, the enemy's remaining ships are revealed).

Feedback: cannon/splash/explosion sounds (synthesized with Web Audio, mute button in the header), ripple animation on misses, fireball on hits, banner call-outs for HIT / MISS / SUNK, screen shake, a fleet tracker for both sides, an event log and a turn indicator. Your win/loss record and settings are kept in `localStorage`.

## Computer opponent

- **Easy**: random shots; fires at neighbours once it scores a hit.
- **Normal**: checkerboard-parity hunting, then targets around hits and extends straight lines of hits.
- **Hard**: probability density. It counts every remaining ship placement consistent with known hits and misses and fires at the most likely cell, weighting placements that cover unresolved hits.

Average shots to sink a fleet in simulation (random fleets): Easy ~63, Normal ~52, Hard ~45.

## Files

| File | Purpose |
| --- | --- |
| `index.html` | Page structure |
| `style.css` | Layout, ships, animations, responsive (desktop/phone) styles |
| `game.js` | Fleet model, board rendering, ship placement and drag/drop |
| `battle.js` | Turn flow, shot effects, trackers, end screen, startup |
| `ai.js` | Computer opponent (also loadable in Node for testing) |
| `audio.js` | Synthesized sound effects |
