A tactical analysis tool for Battleship gameplay, utilizing Probability Density Mapping to determine optimal firing sequences based on remaining fleet data and known cell states.
- Heatmap Generation: Dynamic calculation of ship occupancy probabilities using iterative matrix scanning.
- Constraint Satisfaction: Real-time integration of Hit, Water, and Sunk states to filter valid ship placements.
- Automated Sinking Logic: Recursive identification of contiguous hits to transition units to the Sunk state, automatically flagging surrounding perimeters as Water (tactical exclusion).
- Weighted Heuristic (Stage 2): Aggressive prioritization of cells that explain existing hits, significantly increasing the precision of follow-up shots.
- Language: Python 3.14.3
- Libraries: NumPy (high-performance matrix operations), Matplotlib (GUI & data visualization).
The solver evaluates every theoretically possible placement for each remaining ship type across the grid.
The solver is interactive via mouse events on the Matplotlib canvas:
- Left Click: Mark cell as Water (Miss).
- Right Click: Mark cell as Hit.
- Middle Click (Scroll Wheel): Mark a hit as the "Sinking Blow" (triggers the sinking and perimeter-clearance logic).
This tool shifts the gameplay from guessing to a Constraint-Satisfaction Problem. By visualizing the underlying probability distribution, the user can maximize the expected value of every shot, minimizing the total number of turns required to clear the board.
- clone repository:
git clone https://github.com/GaiusJ/Battleship.git - install dependencies:
pip install -r requirements.txt - start solver:
python BattleShipSolver.py
This is a academic side project.
- Personal & Educational Use: Feel free to explore, learn from, and use this tool for private purposes.
- Commercial Use: Prohibited. If you intend to use this code, the heuristic logic, or any derivatives for commercial purposes or financial gain, please contact me directly for written permission.
