Hi guys, I am working on another assignment and was wondering if anyone could help me by showing me a basic layout in how to complete it. I am pretty confused. Here it is:
A Program
For this program, you are to design a class for representing a rectangular grid and use it to allow a user to query a grid interactively as part of a game.
Background:
Pegboard problems are single-player games played on a grid (or pegboard), in which moves are made by successively jumping and removing pegs from the pegboard. A peg can jump an adjacent peg if there is a slot adjacent to that peg in the opposite direction - horizontally, vertically, or diagonally. After a peg has been jumped, it is removed from the board (and possibly eaten). A typical objective of this problem is to begin with a full pegboard from which one peg has been removed, and determine a sequence of jumps which will result in one peg remaining, perhaps in the position from which the first peg was removed. A popular form of this problem involves a rectangular pegboard with 4 slots on a side (see below), which proves to be a challenging problem for a human being.
For instance, consider the example below, which demonstrates the first few moves of a session:
Pegboard Example
0 1 2 3
+---------+
0 | X X X X |
1 | X X X X |
2 | X X X X |
3 | X X X X |
+---------+
Which peg should be
removed to start? 3 1
Pegboard Example
0 1 2 3
+---------+
0 | X X X X |
1 | X X X X |
2 | X X X X |
3 | X O X X |
+---------+
Enter move: 1 3 3 1
Pegboard Example
0 1 2 3
+---------+
0 | X X X X |
1 | X X X O |
2 | X X O X |
3 | X X X X |
+---------+
Enter move: 2 0 2 2
Pegboard Example
0 1 2 3
+---------+
0 | X X X X |
1 | X X X O |
2 | O O X X |
3 | X X X X |
+---------+
Enter move: 1 1 1 3
A move can be characterized by the attributes (startPos, endPos), which respectively refer to the position of a peg that is about to jump (jumper) and the new position of the jumper. The position of the peg that is jumped and removed can be determined by averaging the respective row and column positions of startPos and endPos, provided those positions describe a legal move.
For instance, in the last panel of the example depicted above, the peg in position startPos=(3,3)can jump over the peg in position (2,3)and land in position endPos=(1,3). The "middle position" of the peg that gets jumped over can be found by averaging the coordinate values of startPos and endPos, i.e, ((1+3)/2,(3+3)/2) = (2,3).
The Assignment:
You will design and implement a class called Grid that represents a pegboard as described above. The underlying main data object in a Grid is a vector of vectors!!! Each row is itself a vector, where each element contains a value that designates either a full or empty cell. A Grid also knows how many rows and how many columns it has, and allows direct access to its grid elements via the [] operator -- that is, the element in row i, column j may be referred to as G[i][j]. A Grid also has an overloaded output operator so that it may be displayed on a console or saved in a file.
Your program should provide instructions for the user, print a copy of the board at each step, and allow the user to indicate the row and column numbers of the start position and end position for the next move. If the move is legal, the pegboard should be updated accordingly; otherwise the user should be prompted to enter a valid move. The user should also be permitted to quit at any time (especially when the game is over!)
Thank you for any help!