The same rules apply as with Project 1: this project is to be your own work.
The Assignment:
Hand-in Requirements:
The Game.

A simple way to keep track of the locations of chutes and ladders is to use the following array:
private int[] cLArray =
{-1, 38, 0, 0, 14, 0, 0, 0, 0, 31, 0,
0, 0, 0, 0, 0, 6, 0, 0, 0, 0,
42, 0, 0, 0, 0, 0, 0, 84, 0, 0,
0, 0, 0, 0, 0, 44, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 26, 0, 11, 0,
67, 0, 0, 0, 0, 53, 0, 0, 0, 0,
0, 19, 0, 60, 0, 0, 0, 0, 0, 0,
91, 0, 0, 0, 0, 0, 0, 0, 0, 100,
0, 0, 0, 0, 0, 0, 24, 0, 0, 0,
0, 0, 73, 0, 75, 0, 0, 78, 0, 0};
Here the array index i goes from 0
to 100 inclusive. Position 0
has no meaning, but otherwise if position i is not zero,
it gives the far end of a chute or ladder starting at i.
A ladder will have cLArray[i] greater
than i and a chute will have cLArray[i]
less than i. For example, cLArray[4] is
a 14, meaning that there is a ladder from
4 to 4.
Similarly cLArray[16] is
a 6, meaning that there is a chute from
16 to 6.
To start the project, you just need a Board class with the array cLArray in it as above and with a method public int getEnd(int position) that will return the value of cLArray[position].
Back in a Chute class, you can keep track of the position of the piece on the board using a variable position, initially 0. Use the Dice class to roll one die, and update position to position + die. Then use getEnd in Board to check if the new position is at the start of a chute or ladder. If it is, change position to the far end of the chute or ladder. You also have to worry about position 100, since the board piece can't go beyond that position, and if you reach position 100 the game is over.
Here are several sample runs of the game: Sample runs.
Add a loop to your program that will repeatedly play the game looking for the following special configuration: the shortest possible sequence of dice throws that will finish a game and go down two chutes. Do not search for this answer by hand, since the only interest is in what you can program.
Hints about this part: Each time you play another game, record the sequence of dice rolls in a String. If the new game is shorter than any you've had before, print this string, but otherwise just discard the string and go on to the next trial game. Here is a sample partial run of a program carrying out the search, though the final results of the search are not included (no games shorter than 14 moves): Sample run.
private void getCoords(int boardNum) {
int rowNum = 10 - (boardNum - 1)/10;
int colNum;
if (((boardNum - 1)/10)%2 == 0) colNum = (boardNum - 1)%10 + 1;
else colNum = 10 - (boardNum - 1)%10;
}
You can use data fields in the class to retrieve these values of
rowNum and colNum. Later in class we
will talk about returning two numbers at once from a function.
private final int X_CORNER = 30; // upper left corner of board (x coord) private final int Y_CORNER = 50; // upper left corner of board (y coord) private final int SIDE = 40; // length of a side of a board squareThe get the center of board postion 42, for example, the above function gives rowNum equal 6 and colNum equal 2. So to get xy coordinates of the center of this board square, in the y direction one goes Y_CORNER amount, then skips over rowNum - 1 squares (of size SIZE) and the goes an additional amount SIZE/2. The calculation for the x direction is similar.