Starting from:

$25

CS213 - Assignment 2 - 2-Player Chess - Solved

  Every piece must know what moves are allowed on it. If a player attempts an illegal move on a piece, your program should not execute the move. Instead, it should print "Illegal move, try again", followed by the usual prompt (for white's move or black's move).

You don't need to have a blank line between an attempted move, the illegal move warning, and the actual correct move. You only need to have a blank line between the board drawing and a move.

•      When a move is made, and it puts the opponent's King under check, your program should print "Check" before prompting for the opponent's move.

•      If a checkmate is detected, your program should print "Checkmate"

•      The last thing before termination should be a display of "Black wins", "White wins" or "draw".

Input
Your program needs to accept input of the form "FileRank FileRank", where the first file (column) and rank (row) are the coordinates of the piece to be moved, and the second file and rank are the coordinates of where it should end up. (See the board example shown above.) All inputs will be on the command line, one move at a time, not through a file.

The figure immediately below should make it clear which rank and file combinations belong to which squares. The white pieces always initially occupy ranks 1 and 2. The black pieces always initially occupy ranks 7 and 8. The queen always starts on the d file.

  

As an example, advancing the white king's pawn two spaces would be input as "e2 e4".

A castling move is indicated by specifying where the king begins and ends. So, white castling king's side would be "e1 g1".

A pawn promotion is indicated by putting the piece to be promoted to after the move. So, promoting a pawn to a knight might be "g7 g8 N". If no promotion piece is indicated, it is assumed to be a queen.

Example of black winning 


More products