Skip to content

irvinodjuana/Battleship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battleship

🚢 Battleship game and AI in JavaScript

Play the game here: https://irvinodjuana.github.io/Battleship/

Overview

Battleship is traditionally a 2-player game in which the players arrange 5 ships of various lengths on a 10x10 board which are hidden to each other. They then alternate choosing coordinates to place "shots" and receive indicators of whether their shots resulted in a "hit", "miss", or "sink".

In this online version, you can instead play against a program set to Easy, Medium, or Hard, and select shots on the screen by clicking on the grid with your cursor. You can arrange your board quickly by clicking "Randomize" until you see a configuration you like and skip the normally tedious part of arranging your ships manually. Once you start, you can see which ships are still in play on the left and right panels.

Good luck and have fun!

AI Strategies

The primary motivation of this project was to implement some of the various automated battleship strategies for fun. The web page mostly exists just because my friends don't typically like to play games through the command line.

These strategies are heavily inspired by this blog post: http://datagenetics.com/blog/december32011/index.html

  • Easy: Randomly choose coordinates without repetition
  • Medium: Search randomly until hit found - then, conduct depth-first search, recursing if node is another hit
  • Hard: Estimate likelihood of each cell containing a ship by "density" - iterating through each remaining ship and incrementing a counter for all possible locations

Screenshots

Selection Phase

Play Phase

Win Phase

About

Battleship game and AI in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published