CS 355
Chess

Due: 11/14/03


This assignment will explore the use of inheritance and dynamic binding to implement variant behaviors.

Chess games are traditionally recorded using a simple notation. Each square on the 8x8 chessboard is named using a lowercase letter a-h to denote the column and a number 1-8 to indicate the row. For example, the starting position on a chess board could be diagrammed as follows:
8rnbqkbnr
7pppppppp
6        
5        
4        
3        
2PPPPPPPP
1RNBQKBNR
 abcdefgh
The pieces are described in more detail below, giving both the symbol used for the piece and the rules governing its movement. Black pieces are represented using lower-case letters. White pieces are represented using upper-case letters.

A move is denoted by giving the starting position of the piece, then a hyphen ("-"), followed by the ending position of the piece. (Actually, the hyphen is replaced by "x" if the move is a capture.) For example, from the position shown above, a common opening move would be "e2-e4", moving the white pawn in the "e" column forward two squares.

We want to prepare a program that will check a transcript of a chess game to be sure that all the recorded moves are legal. At the end of the transcript, the program will print a board diagram similar to the one above and, for debugging purposes, will print intermediate diagrams for each piece being moved showing the legal moves for that piece.

The main portion of the program has already been implemented, as has a class that serves as the root class for all chess pieces. Two of the specific piece kinds have been implemented. You must provide classes to implement the remaining piece kinds.

In the list below, we use the term "starting square" to denote the position occupied by the piece before the move, "final square" to denote the position of the piece after the move, "intervening squares" to denote those squares lying along the line between, but not including, the starting and final squares, "diagonal" to refer to any line traversing an equal number of columns and rows, and "forward" to be moves into increasing row numbers for white pices but decreasing row numbers for black pieces.

Kings
Symbol: K
Moves: A king may move a single square horizontally, vertically, or diagonally from its starting position, provided that the final position is not occupied by a piece of the same color.

A king that has not yet moved in a game has an additional optional move, called castling. The king moves two spaces horizontally, and the rook towards which the king is moving is placed adjacent to the king on the intervening square. Castling can only be done if the rook involved has also not yet been moved in this game, if all squares between the king and rook are empty, if no enemy piece can move onto the starting, intervening, or final square of the king's move.

Queens
Symbol: Q
Moves: A queen may move any number of squares square horizontally, vertically, or diagonally from its starting position, provided that the final position is not occupied by a piece of the same color and that all intervening squares are empty.
Rooks
Symbol: R
Moves: A rook may move any number of squares square horizontally, or vertically from its starting position, provided that the final position is not occupied by a piece of the same color and that all intervening squares are empty.
Bishops
Symbol: B
Moves: A bishop may move any number of squares square diagonally from its starting position, provided that the final position is not occupied by a piece of the same color and that all intervening squares are empty.
Knights
Symbol: N
Moves: A knight may move to any square that is 2 columns and one row from its starting position, or two rows and one column from its starting position, provided that the final position is not occupied by a piece of the same color.
Pawns
Symbol: P
Moves: A pawn may move a single square vertically forward onto an empty destination square, or it may move a single square diagonally forward onto a square occupied by a piece of the opposite color.

A pawn that has not yet moved during the game may also move vertically forward two squares, provided that the final and intervening squares are empty.

The files for this assignment are in ~zeil/cs355/Assignments/chesscpp (or /pub/zeil/cs355/Assignments/chesscpp via anonymous ftp to ftp.cs.odu.edu).

Implement the classes Queen, Rook, Knight, and Bishop in C++.

Submitting

When you are ready to submit your assignment, go here.

You will receive an automatic e-mailed grade report.


Notes

Overview of the files provided:

*.h, *.cpp
The already-implemented portions of the system. You should not change these files. You will want to pay particular attention to pieces.h, which establishes the common protocol for all chess pieces, and king.* and pawn.*, which provide examples of how to implement other pieces.
chessplayer
A compiled version of my solution. Use this to compare your output against mine.
makefile
Project management.