CS 157 Spring 2003               Assignment 7 – Looping – along with some previous topics - basic objects, if’s etc  

100 points

 

Assigned: 03/12/2003

Due: 03/19/2003 (at the start of class – as will be the normal case)

 

Pre-Lab (Do Before Lab):  Bring an empty (or nearly empty) disk. Plan out sequence of statements needed for program.

 

Main Assignment:

 

Now that we are learning loops, we are going to do bigger and better things with chess pieces. Imagine that we are writing a program to determine who is winning a chess game (using fairly simple calculations – we won’t beat Kasparov with this). 

·        You program will use the capabilities of the ChessPiece class provided on the assignments page on my www site.  Note, that on my WWW page, besides the java file, there is a documentation file. This is where you should learn about the class. 

·        Your program will interact with the user, asking for info about each of the pieces that is on the board (piece color (B or W) and piece name (queen, rook, knight, bishop, pawn, or king) until the user says there are no more pieces. 

·        We now have covered enough that you could ensure that the info entered is valid, but to keep this from getting too complicated,  don’t worry about that now. For now, we will assume that the order-entry typists are infallible. 

·        Create chess pieces using the info given by the user, display the chess pieces and their value (as determined by the getValue method from the ChessPiece class). 

·        Also keep track of the total score for the white team, the black team, and for the whole board (white score minus black score), and whether each color ends up having a king on the board.

·        At the end of the program, present whether the board is valid (here just whether each player has one king on the board) and who the current leader is (B or W).

·         See the simple example below (3 pieces isn’t very realistic, but I didn’t want to use too much paper!).

·        Put your name, e-mail address, and date in comments near the top (e.g.  /* Your Name */). 

·        Also, comment any significant code to document it (each loop, each if, and each significant calculation should have a comment).

·        Indent code following standard conventions (indent to show that something is “inside” or “part of” the preceeding code (e.g. inside if’s or loops, or statements continued on a new line). You will need to download ChessPiece.java from my WWW page (if you don’t have it from before).

·        Change the package statement in the file to be appropriate for what package you put it in, otherwise you should not have to modify the file.

·        You will still need the Keyboard file (still obtainable from my WWW page  - or you may still have it on disk). 

Compile the program and remove any errors. Ensure that the program runs correctly. It should run on any set of inputs (test it on more than the example below!!).

               To avoid needless long waits, I recommend doing this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

Hand in:

 

 


Sample Interaction:

What Color is the next piece? (W,or B)

W

What rank is the next piece? (king, queen, rook, bishop, ...

rook

You have entered: WR  Value is: 5

Are there more pieces to be entered (Y or N)?

Y

What Color is the next piece? (W,or B)

B

What rank is the next piece? (king, queen, rook, bishop, ...

king

You have entered: BK  Value is: 100

Are there more pieces to be entered (Y or N)?

Y

What Color is the next piece? (W,or B)

W

What rank is the next piece? (king, queen, rook, bishop, ...

queen

You have entered: WQ  Value is: 10

Are there more pieces to be entered (Y or N)?

y

What Color is the next piece? (W,or B)

b

What rank is the next piece? (king, queen, rook, bishop, ...

pawn

You have entered: BP  Value is: 1

Are there more pieces to be entered (Y or N)?

Y

What Color is the next piece? (W,or B)

W

What rank is the next piece? (king, queen, rook, bishop, ...

bishop

You have entered: WB  Value is: 3

Are there more pieces to be entered (Y or N)?

y

What Color is the next piece? (W,or B)

B

What rank is the next piece? (king, queen, rook, bishop, ...

knight

You have entered: BKt Value is: 3

Are there more pieces to be entered (Y or N)?

y

What Color is the next piece? (W,or B)

W

What rank is the next piece? (king, queen, rook, bishop, ...

pawn

You have entered: WP  Value is: 1

Are there more pieces to be entered (Y or N)?

y

What Color is the next piece? (W,or B)

b

What rank is the next piece? (king, queen, rook, bishop, ...

queen

You have entered: BQ  Value is: 10

Are there more pieces to be entered (Y or N)?

N

Invalid Board - bad number of white kings

White score is: 19

Black score is: 114

Black is leading

Total Board Rating: -95