C M S C     2 1 4
C o m p u t e r   S c i e n c e   I I
S p r i n g   2 0 0 4


Project #2

Due Monday, March 8th, by 11PM

Checklist

Preliminary Material

Project 2 is worth 8% of your grade.

In the previous project, you coded the "set-up" for the game ,EENVG, "Extremely Exciting Non_ Violent Game" (pronounced N-VIG). This project puts the Robot and the Stalker on the board. The Stalker only removes points or ends the game.

The Robot has all of its moves stored in Moves which you have already implemented. Now you need to get the Robot and Board to interact with each other. Once the Robot is working correctly, you need to get the Stalker to move about the board.

The rules of the game are as follows:

  • The Robot is represented by the number 9
  • The Stalker is represented by the number 8
  • The Stalker moves AFTER the Robot
  • In each round of play, the Robot moves and then the Stalker moves.
  • The Robot can move horizontally, vertically or diagonally only. The best way to accomplish this is to find the node in the Moves circularly linked list (that the robot can move to from its currect position) with the largest point value and move the Robot there. She always chooses the 1st move from the list with the largest number of points.The sooner the Robot accumulates enough points and ends the game, the better.
  • If the Robot lands upon a cell with negative points, it loses those points. These are stumbling blocks. The positive values on the board are treasures.
  • primary.input contains the number of points the game will be played to.
  • The game is over when
    • the Robot's points equal or exceed the value in primary.input.
    • The Robot lands on the Stalker
    • The Stalker lands on the Robot (Robot's points are set to 0).
    • The Robot runs out of moves that will give her positive (>0) points
  • The game continues if the Stalker runs out of moves. In this case, the Stalker remains on the last cell it moved to before running out of moves.
  • After the Robot leaves a cell, the points in that cell are set to 0 (zero)
  • After the Stalker leaves a cell, the points in that cell are set to 0 (zero) unless they were negative before the Stalker landed there. In this case, the original negative value is restored to that cell when the Stalker moves on.

Purpose

This project implements the STL vector class as well as a circular doubly linked list. The goals of this project are to:

  1. Understand templates.
  2. Manipulate interacting classes Board, Robot and Stalker.
  3. Understand and implement a logic puzzle

Academic Integrity Statement

Please note that *all* programming projects in this course (including this one) are to be done independently or with the assistance of the instructional staff of this course only.

Please review the policies outlined on the class syllabus concerning the use of class computer accounts and concerning the University's Code of Academic Integrity. The instructors of this course will review the programs submitted by students for potential violations of the Code of Academic Integrity and if it is believed that a violation has occurred it will be referred to the Office of Judicial Programs and the Student Honor Council.

Hardcoding is considered a violation of academic integrity

Style Guide

Students are expected to write "clear and legible" code. Please review the following Style Guide which specifies how students in CMSC 214 are expected to lay out their code:

http://www.cs.umd.edu/class/spring2003/cmsc214/Projects/styleguide.txt

FAQ

Answers to "frequently asked questions" will be posted via the main projects page. Prior to asking a question or submitting a project you should check the FAQ to see if any important information has been covered there. In addition to answers to FAQ's any important information pertaining to a project will be posted on it's FAQ.

E-mailing Questions

DON'T email questions. We cannot keep up with the numerous emails about a project. GO SEE A TA or an instructor during office hours. We will generally NOT respond to email questions about the project.

Project Overview

For this project you will be required, among other things, to write the code for 2 new classes and modify several classes already written:

class 1: Robot

  • Robot is templatized on Pair (the type in Moves)
  • Robot is contained in the Board class
  • The Robot's moves are driven by
    • the moves in the Moves circular, doubly linked list
    • the logic you use to seek out the best move
  • Robot's initial position on the board is in "robot.dat"
  • robot picks up points (treasures) or looses points (stumbling blocks) according to the value in the cell upon which it lands

class 2: Stalker

  • moves about the board sucking up treasures (+ points)
  • it leaves stumbling blocks (- points) unchanged when it moves off of a cell with a negative value
  • its moves are stored in a vector
  • Stalker's initial position on the board is in "stalker.dat"
  • Stalker's moves are in "smoves.dat"

class 3: Moves

  • Moves is templatized on Pair (the type in Node)
  • circular, doubly linked list containing Nodes of Pairs
  • has changed from project 1
  • input for the list is in "moves.dat"

class 4: Mpair

  • a pair of integers indicating the coordinates of a board cell
  • for coordinate [r,c], r indicates the row position and c indicaties the column position
  • each row and column begins at 0
  • has changed from project 1

class 5: Board

  • Board is templatized on the contents of the board ("int" in this case) and the Robot's generic type (Pair)
  • Now contains Robot and Stalker
  • is changed in order to interact with the Robot and Stalker
  • input to the board will be in "board.dat"

class 6: Except

  • exceptions that occur in the above classes
  • 2 are provided, do not change these
  • 3 were written by you for project 1
  • write 3 other exceptions that could occur in your classes
  • you need a total of 8 exceptions
  • Note: exceptions must be thrown in the function in which they occur, but they are NOT caught there. They are caught in main or in the function which calls the function containing the exception.

class 7: Node

  • Node is templatized on Pair
  • has changed from project 1

class 8: Pair

  • no changes

In the class posting accounts (~bt214001) you can find the header
files, data files, and main.cpp for the classes. The following rules
MUST be adhered to:
  • No public functions or (public, protected, or private data members) may be added to the header files.
  • Your output must match our output, an example of which is provided in primary.output
  • You may not change the input - as provided in primary.input
  • Projects submitted after 2 days late will receive a grade of zero.

After copying the header files into your account you should create the corresponding Pair.cpp, Node.cpp, Moves.cpp, Mpair.cpp, Board.cpp, Except.cpp, Robot.cpp and Stalker.cpp files. You will write the code that implements the member functions for these classes. Note: you may NOT change the public methods in the header files but may add private methods as needed. You may NOT add private, public or protected data members to any class other than Except.h.

You must add public methods to Except.h only. However, do not change the public methods provided to you. You will add 3 more exceptions to Except.h and Except.cpp.

In each header file you will find the class with it's data member(s) and member function(s). There is a comment before/around each member function describing what it should do. You are to implement (i.e. write the code for) the member function ABOVE the line

    // YOU MAY PUT ANY PRIVATE METHODS HERE

so that it does what the comment states that it should do and nothing more.

Next you should write 7 unit test files to test each of your classes:

  • testPair.cpp
  • testNode.cpp
  • testMoves.cpp
  • testMpair.cpp
  • testBoard.cpp
  • testRobot.cpp
  • testStalker.cpp

A unit test file should be a main() for a particular class that calls and tests each public method. It also tests the private methods which are called from public methods. Note that when developing/writing code you should do so in parts/modules and test each as you create it (keeping backup copies!). So for example, when writing Node, you also write a testNode.cpp that is the main() for Node.cpp. It should call all public functions and include appropriate output to test that all Node.cpp code works correctly.

And finally you should test your project with the main provided:

main.cpp

Add your own catch clauses to this file. We will run your main but it must diff down to and including the 2 catch clauses that were written for you for exceptions we provided.

It is expected that your output will match our primary.output exactly

Assumptions

You may assume that

  • You may NOT assume that Stalker and Robot are always initialized to a cell with 0 points. Stalker either restores negative points if they are initially negative or whipes them out. Robot starts out with the number of points in the cell she is first placed upon.
  • When printing Robot's moves, 7 per line are printed.
  • All input will be read from a file. For example, moves.dat will hold the allowable moves.
  • There may be multiple lines in any file.
  • The input will not be empty. Each non-empty line will be followed by a newline (carriage return).
  • Each file will contain an EOF marker on the last line.
  • "moves.dat" may contain upper/lower case letters and white space, as well as digits.
  • all other input files, including primary.input will contain integers only
  • for purposes of submitting your program, the board will be 3X3
  • the size of the board may change in subsequent tests for project 2
  • the board will always be a perfect square (nXn)

Hints

Your first step should be going back over project 1 and correcting code that failed our tests or was inefficient or incomplete.

This project has complicated logic because of the interactions among the various classes. Start immediately. A simple logic error can waste a great deal of time. If you run into something that stumps you, put it aside and work on something else, then come back to the code giving you problems.

You may find it easier to remove the templatizing and get the code to work correctly first, then templatize the appropriate classes.

If you work on your class account, tar up your files every day and email them to your wam account. You can always work on the project on the g++ compiler on wam if the detective cluster goes down or is slow.

Sample I/O

You may assume:

  • There are no blank lines in the input file.
  • Each line terminates with a carriage return.
  • The last line contains an EOF marker.

A primary input file and a primary output file are provided in the class posting accounts (in the appropriate directory). You should review these files. They will be named primary.input and primary.output respectively.

Your project will successfully submit if it passes the primary.input.

Your program should generate the corresponding output similar to
primary.output. Additionally, we will test several methods from your code.

When your main program is compiled and run with input redirected so that it gets the contents of the primary input file (primary.input) as input, it should generate output that matches the primary output file. When we test your program we will diff your output (using diff -bwi) with that of the primary output and if it does not match, your program will be considered to not meet the minimum running standards and you will be unable to submit it.

Passing primary does not guarantee a passing grade (70 or above) for your project. Testing your program thoroughly helps.

How to Submit

Provide a makefile that creates an executable file named p2 when the command make p2 is run.

Tar up all necessary files, such as source code, including:

  • all .cpp files
  • all .h files
  • your makefile

submit p2.tar 2

Submit will start accepting project 2 submissions on or about 03/06/04.


See the class syllabus for policies concerning email
Last Modified: February 19, 2004
left up down right home

Web Accessibility