BattleSalvo
a riff off battleship with ai play
As part of Object-Oriented Design, a class I took in Summer 2023, we assigned a two-part project in creating a game called BattleSalvo
.
The twists:
BattleSalvo grids can have height and width dimensions of any value between 6 and 15. The size of the board for each player is identical.
BattleSalvo ships and sizes: carrier
6
, battleship5
, destroyer4
, submarine3
. There may be several of each boat type.The total fleet size may not exceed the smaller board dimension, but must have at least one of each boat type. Fleet size and boat types will be identical between players.
For each turn, each player launches one missile per non-sunk boat remaining in their fleet.
In BattleSalvo, both players select their shots, and the shots are exchanged simultaneously. Games can end in ties!
I created a CLI BattleSalvo game that is adaptable between manual and AI players. The default is between one manual player, the user, and an AI player. It follows MVC[1] conventions and the SOLID[2] principles. There are separate abstract classes for manual player and AI player which extend a common Player interface, and the single controller manages game flow.
It was really interesting to consider the design of the game, as we were provided with a prewritten Player interface that could not be modified.
In the second part of the project, we paired up[3] to extend our BattleSalvo games to allow for play against a server with an AI player. In this part of the project, I used the proxy design pattern[4] to create a ProxyController[5] that connected to a socket and handled all of the received JSON messages from the server. Jackson was the JSON library used, and I created new records and adapted existing classes like Ship and Coord to facilitate serialization. To test these features, we used mocks and appendables.
In the end, we were challenged to upgrade our AI player algorithms and a day in class was dedicated to holding a single-elimination tournament between our BattleSalvo implementations. The strategy I'd set up was to seek out the neighboring cells of recorded successful shots in a starburst pattern. We got through three rounds!