CS 173: Homework 1
Chess

Due Sunday, February 17

In this assignment, you are to complete Lab 7 to create an almost complete game of chess. You should implement the standard pieces, alternate moves between two players, and capture pieces. You do not have to implement (unless you want to) the castling move, check and checkmate, pawn promotion, or the pawn en passant.

Rules of the assignment

Complete Lab 7

If you have not done so, complete lab 7.

Adding opponents

We need to specify a direction for each piece. The direction corresponds to the side for a piece, or the direction the pawns may move. There are two possible values for the direction, up or down. As a result, you use either a boolean, and int, or an enum type to represent the direction.

Modify the ChessPiece class to add an instance variable that stores the piece's direction, add a direction to the constructor parameters, and add a method getDirection. You will need to make the appropriate changes to KnightPiece.

You should modify ChessBoard to keep track of the current direction. Change the actionPerformed method so that only a piece that matches the current direction can be selected and so that once the piece is moved, the current direction is changed.

Create the chess pieces

First you are to create the chess pieces. In the lab, you created the abstract ChessPiece as well as the KnightPiece. The other pieces are:

Note: as mentioned in the lab, the different chess piece classes should not save any value that is saved in the ChessPiece class. Instead, if you need access to one of these values you should call the appropriate method from the parent class.

Play the game

You should create a main method that creates a ChessBoard and populates it with the appropriate pieces of two different colors, each color going in opposite directions. If you do not know the appropriate starting positions for the different pieces, you can do a quick internet search for "chess".