Archive‎ > ‎Fall 2009‎ > ‎Course Project‎ > ‎Buddy Suite‎ > ‎

Milestone 3 - Chess Logic


  • Implement validation of chess moves.
  • Implement chess game logic.

  • Your chess game has to validate moves correctly.
  • Your chess game must have game logic (i.e. verifications for check, checkmate, draw...).
  • You are free to use whatever representation you choose for the board and whatever technique for validating the moves, as long as all (and only) the rules listed below are correctly implemented.

  • 60 pts for the correct chess moves.
  • 40 pts for the game logic (awarded only if the chess moves are present and correct).
  • Up to 20 pts bonus for the elegance and efficiency of the chess board representation.
  • Up to 10 pts bonus for generating a PGN (Portable Game Notation) file for every played game.

Chess Game Rules:

  • There are many variants and different sets of rules in chess. This guide is meant to be a common reference of the rules that will be used in this project (i.e. the rules that your chess validation engine has to implement). Please note that the chess server also validates submitted the moves according to what comes below and thus any deviation in your implementation may result in incompatibilities.
  • Starting a Game

    • At the beginning of the game the chessboard is laid out so that each player has the white (or light) color square in the bottom right-hand side. The chess pieces are then arranged the same way each time. The second row (or rank) is filled with pawns. The rooks go in the corners, then the knights next to them, followed by the bishops, and finally the queen, who always goes on her own matching color (white queen on white, black queen on black), and the king on the remaining square.
    • The player with the white pieces always moves first. Therefore, players generally decide who will get to be white by chance or luck such as flipping a coin or having one player guess the color of the hidden pawn in the other player's hand. White then makes a move, followed by black, then white again, then black and so on until the end of the game.        


  • How the Chess Pieces Move

    • Each of the 6 different kinds of pieces moves differently. Pieces cannot move through other pieces (though the knight can jump over other pieces), and can never move onto a square with one of their own pieces. However, they can be moved to take the place of an opponent's piece which is then captured. Pieces are generally moved into positions where they can capture other pieces (by landing on their square and then replacing them), defend their own pieces in case of capture, or control important squares in the game.
    • The King

      • The king is the most important piece, but is one of the weakest. The king can only move one square in any direction - up, down, to the sides, and diagonally. Click on the ">" button in the diagram below to see how the king can move around the board. The king may never move himself into check (where he could be captured).

    • The Queen
      • The queen is the most powerful piece. If moved she can move in any one straight direction - forward, backward, sideways, or diagonally - as far as possible as long as she does not move through any of her own pieces. And, like with all pieces, if the queen captures an opponent's piece her move is over. Click through the diagram below to see how the queens move. Notice how the white queen captures the black queen and then the black king is forced to move.

  • The Rook
    • The rook may move as far as it wants, but only forward, backward, and to the sides. The rooks are particularly powerful pieces when they are protecting each other and working together!

  • The Bishop
    • The bishop may move as far as it wants, but only diagonally. Each bishop starts on one color (light or dark) and must always stay on that color. Bishops work well together because they cover up each other’s weaknesses.

  • The Knight
    • Knights move in a very different way from the other pieces – going two squares in one direction, and then one more move at a 90 degree angle, just like the shape of an “L”. Knights are also the only pieces that can move over other pieces.

  • The Pawn
    • Pawns are unusual because they move and capture in different ways: they move forward, but capture diagonally. Pawns can only move forward one square at a time, except for their very first move where they can move forward two squares. Pawns can only capture one square diagonally in front of them. They can never move or capture backwards. If there is another piece directly in front of a pawn he cannot move past or capture that piece.

  • Promotion

    • Pawns have another special ability and that is that if a pawn reaches the other side of the board it can become any other chess piece (called promotion). A pawn may be promoted to any piece. [NOTE: A common misconception is that pawns may only be exchanged for a piece that has been captured. That is NOT true.] A pawn is usually promoted to a queen. Only pawns may be promoted.

  • Castling

    • One other special rule is called castling. This move allows you to do two important things all in one move: get your king to safety (hopefully), and get your rook out of the corner and into the game. On a player’s turn he may move his king two squares over to one side and then move the rook from that side’s corner to right next to the king on the opposite side. (See the example below.) In order to castle, however, it must meet the following conditions:

      • it must be that king’s very first move
      • it must be that rook’s very first move
      • there cannot be any pieces between the king and rook to move
      • the king may not be in check, pass through check or end up in check
      • the king and the rook must be on the same rank (cannot castle with a promoted pawn for instance)

  • Notice that when you castle one direction the king is closer to the side of the board. That is called kingside. Castling to the other side, through where the queen sat, is called castling queenside. Regardless of which side, the king always moves only two squares when castling.

  • En Passant

    • The last rule about pawns is called “en passant,” which is French basically means “in passing”. If a pawn moves out two squares on its first move, and by doing so lands to the side of an opponent’s pawn (effectively jumping past the other pawn’s ability to capture it), that other pawn has the option of capturing the first pawn as it passes by. This special move must be done immediately after the first pawn has moved past, otherwise the option to capture it is no longer available.

  • Check and Checkmate

    • As stated before, the purpose of the game is to checkmate the opponent’s king. This happens when the king is put into check and cannot get out of check. There are only three ways a king can get out of check: move out of the way (though he cannot castle!), block the check with another piece, or capture the piece threatening the king. If a king cannot escape checkmate then the game is over. Customarily the king is not captured or removed from the board, the game is simply declared over.

  • Draws

    • Occasionally chess games do not end with a winner, but with a draw. There are 5 reasons why a chess game may end in a draw:

      • Draw by stalemate - The position reaches a stalemate where it is one player’s turn to move, but his king is NOT in check and yet he does not have another legal move.
      • Draw by agreement - The players may simply agree to a draw and stop playing.
      • Draw by impossible checkmate - A position arises in which neither player could possibly give checkmate by a series of legal moves, the game is a draw. This is usually because there is insufficient material left, but it is possible in other positions too. Combinations with insufficient material to checkmate are:
  • king versus king
  • king and bishop versus king
  • king and knight versus king
  • king and bishop versus king and bishop with the bishops on the same color. (Any number of additional bishops of either color on the same color of square due to underpromotion do not affect the situation.)
      • Draw by triple repetition - An identical position has just occurred three times with the same player to move, or will occur after the player on turn makes his move, the player on move may claim a draw. In such a case the draw is not automatic - a player must claim it if he wants the draw. When the position will occur for the third time after the player's intended next move, he writes the move on his scoresheet but does not make the move on the board and claims the draw. A position is considered identical to another if the same player is on move, the same types of pieces of the same colors occupy the same squares, and the same moves are available to each player; in particular, each player has the same castling and en passant capturing rights. (A player may lose his right to castle; and an en passant capture is available only at the first opportunity.) If the claim is not made on the move in which the repetition occurs, the player forfeits the right to make the claim.
      • Draw by fifty-move rule - In the previous fifty moves by each side, no pawn has moved and no capture has been made, a draw may be claimed by either player. Here again, the draw is not automatic and must be claimed if the player wants the draw. If the player whose turn it is to move has made only 49 such moves, he may write his next move on the scoresheet and claim a draw. As with the threefold repetition, the right to claim the draw is forfeited if it is not used on that move, but the opportunity may occur again.
  • Note that perpetual check (i.e. when one player is in a position to give a series of checks from which the other player cannot escape) is not considered draw! Instead, this situation is handled either by the draw by agreement or the fifty-move rule.