UMBC CMSC 202
UMBC CMSC 202 CSEE | 202 | current 202

CMSC 202 - Project 3

Queueing up for Success

Assigned Sunday October 29, 2006
Design Due Sunday November 5, 2006 at 11:59 pm
Program Due Sunday November 12, 2006 at 11:59pm
Updates
  • November 1 - You may use a struct for your Node and/or "Square" [optional class] classes
  • October 30 - Example Output included

Objectives


General Project Description

You have just recently started an internship with GamesCo - a local interactive game company and your supervisor wants you to create an electronic version of the old BattleShip game. You will be responsible for creating the interface that users will see, all of the game logic, a networking component that will allow users to play each other head-to-head, and an artificial-intelligence component that will allow users to play the computer.

Each phase of this project will add on a different component so that by the end of the five phases, you will have a completely operational BattleShips game.

Project Description

Project Modifications

Functional Description

Your application must function in the same way as described in Project 2 with some minor changes, within the game-playing portion, play proceeds as follows:

Artificial Intelligence

In order to make the game more exciting, we need to add a little intelligence to the computer component. One of the basic strategies of BattleShip is that once you have detected a hit, you should try the squares around that square. We will use a Queue (FIFO: first in, first out) in order to select and store a sequence of "guesses" for the computer. Using a Queue to represent the set of "next guesses" is a Breadth-first searching technique that is common to basic Artificial Intelligence systems.

Queue's have two basic operations:
enqueue - add an item to the back of the queue and
dequeue - remove an item from the front of the queue.

When the computer gets a hit, it must enqueue the 4 surrounding squares onto the queue. It must enqueue them in the following order: above, right, below, left. If one or more of these four squares have already been guessed, they must be enqueued anyway (we will take care of removing them later). If one or more of these four squares does not exist (outside the board), it must NOT be enqueued.

When it is the computer's turn, it must first look to see if there are any squares currently listed on the Queue, if there are, it must remove them one at a time until a square is found that has not previously been guessed. If no such squares are found, and the Queue is exhausted, then the Computer should default to the "random" strategy that it employed for the previous project.

Design and Implementation Requirements

Classes

You are required to keep the Human, Computer and Board classes from Project 2. However, you may make any changes you desire or are necessary to support the additional requirements of this project.

You may also find it useful to introduce small "helper" classes to represent a square of the board that was selected or other small tasks. These classes need not implement the Big Three nor be dynamically allocated.

You are also required to add a Queue class that relies upon a linked structure to help the Computer determine which square to attack next. Queue objects need not be dynamically allocated, however, their internal structure will be.

Queue Class

The basic design of a Queue class supports the following functionality: You will most likely need to implement additional functions, operators, etc. in order to complete the Queue class. Since the Queue will have dynamic memory, you are also required to include the Big Three.

You are required to implement your Queue as a dynamically linked structure (much like the Linked List you studied in 201). Your Queue class will need a smaller "helper" class that represents a single Item (or Node) in the Queue. Your Queue class will also require a head pointer that points to the first Item in the Queue and a tail pointer that points to the last Item in the Queue. Each Item in the Queue will need a pointer to the next Item in the Queue.

The last Item in the Queue should have its 'next' pointer set to NULL. If no Items are in the Queue, then the head and tail pointers must be NULL. Below is an illustration of what several Queues might look like.

To assist in the debugging of your Queue class, you are encouraged to implement the overloaded insertion operator - so that you can print all of the Items in the Queue.

In designing and implementing your Queue class, attempt to keep it as general as possible - we may reuse this in a future project (hint, hint).

Overloaded Operators

All overloaded operators must operate on OBJECTS of each class, NOT on pointers to an object. You should remember to dereference pointers before attempting to use overloaded operators on them.

Insertion Operator

You are required to overload the insertion operator for your Board class. You should take advantage of any code you have already written and reuse it. Do not duplicate code. Replace any calls to existing "Print" (or similar) functions with calls using the insertion operator. You may choose to delete any functions that accomplish the same task.

Extraction Operator

You are also required to overload the extraction operator for the Board class. Again, reuse any existing code. Do not duplicate code. You may choose to delete any existing methods that accomplish the same task. The stream passed into the extraction operator should be an open file.

Dynamic Memory

You are required to modify your existing system to use dynamic memory in the creation and maintanence of user-defined objects. All instances of Humans, Computers, and Boards must be created dynamically.

Each of these classes must have the Big Three implemented and used appropriately. All instances of dynamic memory in these classes should be properly allocated and deallocated in the Big Three. Even if your class does not allocate dynamic memory, you must overload the Big Three.

You will need this component working for Project 4.

Example Output

Updated!

Here is an example of what your output might look like. You need not adhere to this format exactly, but it gives you a good idea of what we are looking for. Feel free to add labels to each board to differentiate the two or use your own wording for interaction with the user.

Welcome to Battleship! The goal of this game is to completely destroy your opponent's ships. By alternating turns, you will be able to attack squares on your opponent's board. If you hit a ship, the system will report this. If you miss, the system will report this. 0 1 2 3 4 5 6 7 8 9 A o o o o o o o o o o B o o o o o o o o o o C o o o o o o o o o o D o o o o o o o o o o E o o o o o o o o o o F o o o o o o o o o o G o o o o o o o o o o H o o o o o o o o o o I o o o o o o o o o o J o o o o o o o o o o The Computer has missed at (G, 4)! 0 1 2 3 4 5 6 7 8 9 A o o o o o o o o o o B o o o o o o o o o o C o o o o o o o o o o D o o o o o o o o o o E o o o o o o o o o o F o o o o o o o o o o G o o o o o o o o o o H o o o o o o o o o o I o o o o o o o o o o J o o o o o o o o o o Where would you like to attack? (row column) (ex: A 1) A 1 You have missed at (A, 1)! 0 1 2 3 4 5 6 7 8 9 A o o o o o o o o o o B o o o o o o o o o o C o o o o o o o o o o D o o o o o o o o o o E o o o o o o o o o o F o o o o o o o o o o G o o o o M o o o o o H o o o o o o o o o o I o o o o o o o o o o J o o o o o o o o o o The Computer has missed at (D, 4)! 0 1 2 3 4 5 6 7 8 9 A o M o o o o o o o o B o o o o o o o o o o C o o o o o o o o o o D o o o o o o o o o o E o o o o o o o o o o F o o o o o o o o o o G o o o o o o o o o o H o o o o o o o o o o I o o o o o o o o o o J o o o o o o o o o o Where would you like to attack? (row column) (ex: A 1) A 2 You have hit a ship at (A, 2)! 0 1 2 3 4 5 6 7 8 9 A o o o o o o o o o o B o o o o o o o o o o C o o o o o o o o o o D o o o o M o o o o o E o o o o o o o o o o F o o o o o o o o o o G o o o o M o o o o o H o o o o o o o o o o I o o o o o o o o o o J o o o o o o o o o o The Computer has missed at (J, 8)! 0 1 2 3 4 5 6 7 8 9 A o M H o o o o o o o B o o o o o o o o o o C o o o o o o o o o o D o o o o o o o o o o E o o o o o o o o o o F o o o o o o o o o o G o o o o o o o o o o H o o o o o o o o o o I o o o o o o o o o o J o o o o o o o o o o Where would you like to attack? (row column) (ex: A 1) B 2 You have hit a ship at (B, 2)! [Cut for length]

General Tips


Project Design Assignment

Your project design document for this project must be named p3design.txt. Be sure to read the
design specification carefully. Submit your design in the usual way: submit cs202 Proj3 p3design.txt Remember - the design is due ONE WEEK before the project. Late designs will not be accepted.

Project Makefile

The "make" utility is used to help control projects with large numbers of files. It consists of targets, rules, and dependencies. You will be learning about make files in lab. For this project, the makefile will be provided for you. You will be responsible for providing makefiles for all future projects. Copy the file makefile from Ms. Wortman's public directory to your directory.

When you want to compile and link your program, simply type the command make or make Proj3 at the Linux prompt. This will compile all necessary .cpp files and create the executable named Proj3.

The make utility can also be used for compiling a single file without linking. For example, to compile Proj3.cpp, type make Proj3.o.

In addition to compiling and linking your files, make can be used for maintaining your directory. Typing make clean will remove any extraneous files in your directory, such as .o files and core files. Typing make cleanest will remove all .o files, core files, Proj3 executable and backup files created by the editor. More information about these commands can be found at the bottom of the makefile.

If you are building your own makefile, you MUST use the /usr/local/bin/g++ compiler to compile and build each file. Do not depend on setting your default compiler to be this compiler, the grader may use a different compiler. There are two compilers on the GL systems, and you are required to use the one located at /usr/local/bin/g++.


Grading

The grade for this project will be broken down as follows. A more detailed breakdown will be provided in the grade form you receive with your project grade.

85% - Correctness

This list may not be comprehensive, but everything on this list will be verified by the graders.

15% - Coding Standards

Your code adheres to the
CMSC 202 coding standards as discussed and reviewed in class.

Project Submission

Steps for Submission

  1. submit all files
  2. submitls to verify they are in the remote directory
  3. submitmake to build your files remotely
  4. submitrun to run your files remotely
Assuming you've used the recommended file names, then to submit your project, type the command submit cs202 Proj3 Proj3.cpp Proj3Aux.cpp Proj3Aux.h Makefile The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile your project (using the makefile) are listed. You need not submit all files at the same time. You may resubmit your files as often as you like, but only the last submittal will be graded and will be used to determine if your project is late. For more information, see the projects page on the course website.

You can check to see what files you have submitted by typing

submitls cs202 Proj3

Be sure to build your project once it has been submitted using the submitmake command, so that you know that all of the files are there and are the most up-to-date versions:

/afs/umbc.edu/users/d/a/dana3/pub/CMSC202/submitmake cs202 Proj3

Test your program to ensure that all files are the most recent versions:

/afs/umbc.edu/users/d/a/dana3/pub/CMSC202/submitrun cs202 Proj3

Details on Submit Tools.

Remember -- if you make any change to your program, no matter how insignificant it may seem, you should recompile and retest your program before submitting it. Even the smallest typo can cause compiler errors and a reduction in your grade.

Avoid unpleasant surprises!

Be sure to use the submitmake and submitrun utilities provided for you to compile, link and run your program after you've submitted it.


Last Modified: Wednesday, 01-Nov-2006 10:23:41 EST