UE CS 215 - CS 215 - Fundamentals of Programming I

Unformatted text preview:

CS 215 - Fundamentals of Programming IISpring 2008 - Project 440 pointsOut: February 20, 2008Due: March 17, 2008 (2nd Monday after spring break)Reminder: Programming Projects (as opposed to Homework problems) are to be your own work. See syllabus for definitions of acceptable assistance from others.The Game of DotsDots is a simple game usually played with pencil and paper. The playing field is a two-dimensional array of dots and the only valid move is to connect two adjacent dots horizontally or vertically. (No diagonal moves are allowed.) Players take turns connecting dots, except if a player connects two dots that complete a box (i.e., the top, bottom, left, and right sides of the box have been drawn), then the player fills in the box with her initial and gets a free turn. When all boxes have been filled in, the player who has claimed the most boxes wins. (Ties can be avoided by making sure that the number of possible boxes is odd). In the following example, the first row shows the first four moves of a 3x3 dots game. (The size of the game is number of boxes.) The players are A and B, and they alternate turns. The second row picks up the same game after several more moves. The first board in the row is before B's turn. B makes a move, yielding the second board, and A completes the box, yielding the third board. A now moves again, completing another box (fourth board), and must move again (fifth board). It is now B's turn, and B will be able to complete 1 box, but must move again, and any additional move will give player A three more boxes. The final score will be A-5, B-4. To write a computer program for playing Dots, instead of keeping track of a grid of dots, we need to keep track of a grid of boxes. Each grid location has is a box that has 4 sides (called top, bottom, left, and right), initially undrawn, and a label, initially blank. Adjacent boxes share a common side. For example, if two boxes are side by side, the right side of the left box is the same as the left side of the right box. Play is conducted as follows: Consider the following specification for a BoxGrid class that represents the Dots playing field. Each grid location contains a Box object, that contains information regarding the state of the box. (The Box class will be provided and is explained below.) Grid locations are given as coordinates (row, col) where (0,0) is the upper left-hand corner of the grid. Specification for BoxGrid Class Data Attributes Revised: 02/23/08 1 of 9For this project, a BoxGrid is modeled using a dynamically-allocated two-dimensional array of Boxes to allow grids of differing sizes to be created. In addition, to facilitate reporting the score of the game, the BoxGrid class keeps track of the player's names, represented by a single character. Thus the data attributes include at least those shown below. You may add additional appropriate attributes.Objects Type Namenumber of rows int numRowsnumber of columns int numColumnsfirst player's namecharplayer1second player's namecharplayer2pointer to gridBox**gridOperations ● Explicit-value constructor - receives the number of rows and columns, and the “names” of two players. Default values are given below. Throws a RangeError exception if initialRows or initialCols is less than 3 (to make sure the grid is large enough) or if the total number of Boxes is not an odd number (so that there always is a winner).It should dynamically allocate a two-dimensional Box grid of the specified size. Note that since the Box class has a default constructor, the elements of the grid will be initialized automatically.Analysis Objects Default Type Kind Movement Namenumber of rows 3 int variable received initialRowsnumber of columns 3 int variable received initialColsfirst player's name 'A' char variable received initialPlayer1second player's name 'B' char variable received initialPlayer2● Copy constructor - creates a new BoxGrid that is identical to an existing one. Analysis Objects Type Kind Movement Nameoriginal BoxGrid object BoxGrid variable received original● Destructor - deallocates the grid Analysis - no objects ● operator= - overloaded assignment operator function. Makes an existing BoxGrid object identical to the original BoxGrid object. Analysis Objects Type Kind Movement Nameoriginal BoxGrid object BoxGrid variable received originalthis BoxGrid object BoxGrid variable returned*thisRevised: 02/23/08 2 of 9● GetRows - returns the number of rows in the grid Analysis Objects Type Kind Movement Namenumber of rows int variable returned numRows● GetColumns - returns the number of columns in the grid AnalysisObjects Type Kind Movement Namenumber of columns int variable returned numColumns● GameOver - passes back the scores of the two players and returns true if the game is over, false otherwise Analysis Objects Type Kind Movement Namefirst player score int variable passed back p1scoresecond player scoreint variable passed back p2scoreis game over? bool variable returned ---● Write - outputs the BoxGrid in a two-dimensional grid to an output stream as shown in the example run below. Note that since the Boxes in the grid share sides, only two connected sides need to be output for each Box with special cases for the remaining edges of the grid. For example, if the bottom and right sides are output, then the top of the first row and the left side of the first box of each row are special cases.Analysis Objects Type Kind Movement Nameoutput stream ostream variable received & passed back out● DrawTop - draws in the top side of Box at grid location(row, col). If drawing in this side has caused a box to be completely drawn in, fill in the label of the box with player and return true, otherwise return false. Throws RangeError if row or column index is out of range. Throws DuplicateError if the side has already been drawn in. Note that since Boxes share sides, drawing in a side may cause an adjacent Box's side to be drawn that may cause the adjacent box to be completely drawn in.Analysis Revised: 02/23/08 3 of 9Objects Type Kind Movement Namerow index int variable received rowcolumn index int variable received colplayer's name char variable received playercompleted box? bool variable returned -----● DrawBottom, DrawLeft, DrawRight – same as DrawTop except they draw in the bottom, left, and right sides, respectively.Assignment The Box class and the Exception classes are provided for this assignment. They may


View Full Document

UE CS 215 - CS 215 - Fundamentals of Programming I

Documents in this Course
Lecture 4

Lecture 4

14 pages

Lecture 5

Lecture 5

18 pages

Lecture 6

Lecture 6

17 pages

Lecture 7

Lecture 7

28 pages

Lecture 1

Lecture 1

16 pages

Lecture 5

Lecture 5

15 pages

Lecture 7

Lecture 7

28 pages

Load more
Download CS 215 - Fundamentals of Programming I
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 215 - Fundamentals of Programming I and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 215 - Fundamentals of Programming I 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?