This project is based on the popular game, Battleship. Players call out coordinates to hit or miss a part of a ship. The first player to sink all their opponent’s ships wins.
A mid-game position for Battleship is displayed below. (Please note that the opponent’s board is at the top, where their ships are not visible, and the player’s board is at the bottom, where their ships are shown. You can check your Hits (H) or Misses (M) on the opponent’s board.)
This script allows you to play the game against an AI opponent or simulate any number of games (AI vs AI). The AI algorithms implemented are as follows:- Greedy algorithm
- Minimax algorithm with alpha-beta pruning
- Custom Probability (custom made heuristic-based algorithm for Battleship)
For an AI algorithm to demonstrate any signs of intelligence while playing, it must consistently outperform random guessing. Consequently, all benchmarking results are based on comparing the AI opponent against random guessing. The table below presents the results:
- Install Python (If you don't already have it) then download the battleship.py file.
- Comment or Uncomment "play_games()" or "simulate_multiple_games()" functions to switch between play or simulate, respectively. These functions are found at the end of the file.
- Type and enter
python battleship.pyin a terminal to run the script!
########################################################

