# Battleship

A browser Battleship game, player vs computer. It's plain HTML, CSS and JavaScript with no build step and no dependencies.

## Run
Open `index.html` in a browser, or serve the folder with something like `python3 -m http.server`.

## How to play
1. **Place your fleet** (Carrier 5, Battleship 4, Cruiser 3, Submarine 3, Destroyer 2):
   - **Drag** a ship from the dock onto your board. This works with mouse or touch.
   - Or **tap/click** a ship in the dock to select it, then tap a cell. The cell is the ship's top/left end.
   - **Rotate** with the Rotate button, the `R` key, or a right-click on your board. You can rotate while dragging.
   - Drag a ship that's already placed to move it, or tap it to pick it back up.
   - **Random** places the whole fleet for you and **Clear** empties the board.
2. Press **Start Battle**, then click cells on *Enemy Waters* to fire.
3. Hits, misses and sinkings each get their own animation and sound. Sounds are synthesized with WebAudio, and 🔊 mutes them. On phones that support it, hits also vibrate. The pill at the top shows whose turn it is.
4. Sink all five enemy ships to win. At the end, a win/lose screen shows your stats and a **Play Again** button.

## Computer strategy
The AI uses a probability-density approach. On each turn it counts every legal position for each ship still afloat, given the misses and sunk ships so far.
- **Hunt mode:** it fires at the most likely cell, with a slight checkerboard-parity bias.
- **Target mode:** after an unsunk hit, it only counts placements that pass through its hits, weighted heavily. This way it follows the line of the ship until it sinks.

## Files
- `index.html` – page layout
- `style.css` – styling, animations and the responsive layout
- `game.js` – game logic, placement, AI and sound
