During the Apprentice Stage (practical exercises in weeks 3, 4, 6, & 7) most of the required classes were completed and tested. During the Master Stage, these classes will be integrated and new classes will be added to produce a fully automated computer simulation of a multiplayer game of Battleships.

Final Product: an object-oriented C++ program that implements a multiplayer computer simulation of Battleships as described below.

UML Class Diagram

See image. See UML Diagram.

In the UML class diagram on the previous page, plain (white) classes are those that have already been implemented during the Apprentice stage; the green and gold classes will be completed during the Master stage as described below (gold represents the opportunity for a high distinction grade).

Classes shown in gray could be implemented during later practical exercises and are not part of the final product to be submitted for assessment; they are shown only for the purposes of comparison and contrast when discussing the design and functionality of the classes that are to be implemented.

Local Class

Local is an abstract class that defines the responsibility of a local Battleships player. It is abstract because it does not define all of the pure virtual methods of the pure abstract Player base class. A Local player is either a Human with a direct interface to the computer (e.g. keyboard and mouse) or a Computer algorithm running on the computer that is managing the Game. By contrast, a Remote player represents a Player entity that interfaces with the computer that is managing the Game via the internet (or some other peer-to-peer communications protocol).

The Local player has a name, a board, and a fleet of ships. It also manages an array of boards for each of its opponents; on these boards, the results of all attacks are recorded (during the call to setResult). The array of boards is managed using the Standard Template Library map container. The Blackboard directory for the semester assignment includes an example program

example_map.cpp

that demonstrates the use of the map class.

The Local player also maintains a pointer to a PlaceFleet instance that defines how the fleet of Ships is placed on myBoard. In a full implementation of the Battleships game, a Human user may manually choose where the Ships are placed on the Board. This behaviour could be implemented by the ManualFleet class, which inherits the PlaceFleet abstract base class and implements the getPlace method. In contrast, the Computer player would always use the RandomFleet class that was implemented in Week 6. The encapsulation of the ship placement algorithm using a family of classes (with an abstract base class) is known as the “Strategy” or “Policy” design pattern.

For this assignment, only the RandomFleet strategy is required. The Local player takes ownership of the PlaceFleet instance and should destroy this resource when needed.

The methods of the Local player are used as follows:

  • resizeBoard : At the start of a game (i.e. during initialization) this method will be used to resize the board and construct the fleet of ships using the buildStandardFleet function provided in Week 6. The second argument to buildStandardFleet should be the smaller of the number of rows and number of columns. If the placement attribute has already been set, then it should be used to place the fleet on the board.
  • Player methods: The remaining six methods should behave as described in the practical exercise for Week 7.

Derived classes that inherit the Local class will implement the remainder of the Player methods.

Computer Class

The Novice class is a concrete class that represents a novice game-playing algorithm. It is concrete because it implements the last of the pure virtual methods of the pure abstract Player base class.

The getAttack method should simply return an Attack instance with the name of a randomly selected opponent and a valid board Coordinate.

Expert Class (high distinction)

The Expert class is a concrete class that represents an expert game-playing algorithm. It should implement the getAttack method using a strategy that is better than simply random.

Battleships Arena

You must write a program that demonstrates the proper initialization, execution, and completion of a game of Battleships by running a fully automated simulation that includes three Novice players, each with a 12x16 board. Your program should run the simulated game 1000 times and count the number of times that each of the three players loses (i.e. count the number of times each player’s fleet is destroyed). To confirm that each Novice player loses approximately 1 in 3 games, the number of losses should be reported at the end of the program; e.g.

Player A lost 318 times
Player B lost 340 times
Player C lost 342 times

(The numbers will be different each time the program is run.)

For a High Distinction grade, your program should also support the option to substitute one of the Novice players with an Expert. The simulation should clearly demonstrate that the Expert player loses significantly fewer games than the Novice opponents.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.