3 min read

BattleSalvo

Table of Contents

As part of Object-Oriented Design, a class I took in Summer 2023, I had a two-part project to create a game called BattleSalvo. It was loosely based upon battleship, and the implementation details were left to us!

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, battleship 5, destroyer 4, submarine 3. 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 game following MVC1 conventions and SOLID2 principles that is adaptable between human and AI players. The default setting is between one manual player (the user) against an AI player. There are separate abstract classes for manual player and AI player which extend a common Player interface, and a 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.

UML design

In the second part of the project, we extended 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 pattern3 to create a ProxyController4 that connected to a socket and handled all of the received JSON messages from the server. I created java records and adapted my existing classes like Ship and Coord to facilitate serialization. To unit test and integration test these features, I used mocks and appendables.

In the end, we were challenged to upgrade our AI player algorithms. A lecture at the end of the semester 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. It got through three rounds!

Footnotes

  1. model, view, controller architecture ā†©

  2. five principles of object-oriented programming: read more here ā†©

  3. read more here ā†©

  4. I used it to execute code before interacting with the primary logic of the AIPlayer class. ā†©