[an error occurred while processing this directive]

Assignment 03

  1. Due Date
  2. Download Files
  3. Description
  4. Submission
  5. Test Compile

Due date

This assignment is due Monday, October 30th at 4:00pm.

Important Note: Late assignments will not be accepted!


Download Files

Download the file A03.zip and extract the files to the cs133 folder on your Home directory. You will use these files to complete this assignment. These files contain methods which we expect to be implemented without changes being made to the method signatures. You are allowed to add helper method.


Description

“Eight Men on a Raft” is a puzzle played on a 1x9 Board (the “raft”), with four red pegs and four blue pegs (the “men”). Initially, all the red pegs are placed at the right end of the Board and all the blue pegs are placed at the left end of the Board, as follows:

The goal of the puzzle is to re-arrange the Board, moving one peg at a time, until all the red pegs are at the left end and all the blue pegs are at the right:

Blue pegs may only move right, and red pegs may only move left. Subject to these constraints, pegs may be moved in two ways:

  1. moving into an immediately adjacent empty square, or

  2. jumping exactly one peg of the opposite colour onto the next empty square. The jumped peg is not removed from the Board.

Provided the moves are legal, pegs may be moved in any order. For example, two blue pegs may be moved before a red peg is moved; it is not necessary to alternate between blue and red.

Moving a peg on the Board class is a two-step process. First, the user clicks on a peg to select it. When a peg is selected its colour is temporarily changed to yellow. Second, the user clicks on an empty square. If the move is legal, the peg is moved to the empty square and its colour is restored. Here is an example of a board with a selected peg:

Here is an example of the board after the peg has moved:

If the user attempts an illegal move after selecting a peg, the puzzle should display a specific message explaining why the move is illegal and reset the selected peg to its original colour. This message should be removed on the next legal move.

If the user clicks on the empty square without first clicking on a peg, then an explanatory message must be displayed, and the next click must be recognized as the beginning of a new move.

If the user clicks on a peg that has already been selected (i.e., is already yellow), then the peg should be unselected and reset to its original colour without any message.

If no more legal moves are available, the puzzle should inform the user. If the user solves the puzzle, a congratulatory message should be displayed.

Implement this puzzle in the file EightMenOnARaft.java. You must use a 1-dimensional array of Man objects, where a Man simply contains a single boolean instance variable indicating if it is red or blue. Use a null reference in the array of Man objects to indicate the empty square.

We have provided you with the complete files Man.java and MainGame.java. Do not change these files — you cannot submit them, and we will use our own copies when we run your so assignment, so any changes you might have made in your copies will be lost. You may only write code in the file EightMenOnARaft.java.

Be sure to document the code you write as described in the CS 133 Programming Style Guide.


Submission

Electronic Submission

This assignment will be submitted electronically. Go here for information on how to submit files electronically.

Files to Submit

You may submit the file EightMenOnARaft.java as many times as you like prior to the submission deadline; a later submission replaces any previous submission. Submitting early ensures that you are able to submit, and that you will receive some credit if you inadvertently fail to submit your final version of EightMenOnARaft.java by the submission deadline.

Late submissions will not be accepted, and no submissions will be accepted via e-mail. It is your responsibility to ensure, prior to the submission deadline, that the submission process works for you, and it is your responsibility to make your final submission sufficiently in advance of the submission deadline as to ensure that there is an adequate margin to allow for unexpected delays.

We will be compiling and running your submission. Be sure the your submission compiles.

After you have gone through the steps for electronic submission (by running an X11 window and executing the submit command), if you want to check to see what files have successfully been electronically submitted, click the button below and enter your Quest password.



Compilation Request

Select the assignment number and press the button to request that the files for the specified assignment be compiled and run. This facility is here to allow you to ensure that you have:

  1. submitted all required pieces of code
  2. no compilation errors
  3. no package names

You may not request testing for a particular assignment once its late deadline has passed. The results will be emailed to the specified userid upon the next scheduled test run (every 10 minutes).

[an error occurred while processing this directive]