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:
| 8 | r | n | b | q | k | b | n | r |
|---|---|---|---|---|---|---|---|---|
| 7 | p | p | p | p | p | p | p | p |
| 6 | ||||||||
| 5 | ||||||||
| 4 | ||||||||
| 3 | ||||||||
| 2 | P | P | P | P | P | P | P | P |
| 1 | R | N | B | Q | K | B | N | R |
| a | b | c | d | e | f | g | h |
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.
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.
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.
Implement the classes Queen, Rook,
Knight, and Bishop in C++.
You will receive an automatic e-mailed grade report.