Assignment 5: Let's Play a Game

Saw movie references are still hip, right? ... right? ... guys???

The premise of this assignment will be simple enough, although I'm make sure to explain the specifics and details later for those who need it: we're going to build a chess game.


For those unaware: Chess is (traditionally) a 2-player strategy game played on a 8x8 black-and-white checkerboard, with it's origins dating back to the 6th century. There are six unique types of "piecees": king, queen, knight, bishop, rook, and pawn. There's only one king and queen piece for each player. The win-condition is defined by "checkmate": a state of the game-board in which the king cannot move to any square and escape an attack from an enemy piece. "Attacks" are defined as when one player's piece moves to occupy the enemy's piece's place on the board, removing the enemy's piece from the game.

A part of me half-expects everyone to roll their eyes at this excessive level of explanation, but I also assume everyone knows the opening theme song to Fresh Prince of Bel-Air by heart... oh how I have been wrong before.

The Pieces

With the exception of the Knight piece, no piece you control can move past or "jump" over other pieces you control. You can occupy or "attack" an enemy piece if they are within moving distance, but cannot attack a piece beyond it.

  • Pawns: each player will have eight pawns stretching the length of their side of the board, on their second row. Pawns can only move forward (towards the enemy side of the board), and can only "attack" diagonally. You are absolutely welcome to ignore implementing En Passant , which I barely understand anyway.

  • Rooks: each player will have two rooks, at either end of their first row or "home" row. These pieces can move an unlimited number of spaces in straight lines. (For chess savy players, we are going to ignore "castling" for this assignment.")

  • Knights: each player will have two knights, next to their rooks. Knights movee in L-shaped movements, going two spaces in one direction, then landing on a space on either side of that end. Knights are the only chess picees who can "jump" over other pieces on the board.

  • Bishops: each player will have two bishops, next to their knights. Bishops can move an unlimited number of spaces in strictly diagonal directions.

  • The Queen: each player will have one Queen piece, placed "on their color" -- the player with white pieces will have the Queen on the white square near the middle of their home row. The most powerful piece, the Queen can move an unlimited number of spaces in straight lines and diagonal directions.

  • The King: each player will have one King piece, placed "off their color", next to the Queen piece. The most important piece on the board, the King can only move one space in any direction. Additionally, they cannot move to a space on the board that could be attacked on the enemy's next turn.

Development Process

You'll first want to start with designing your board and arranging each of your chess pieces. While the physical checkerboard is strictly black-and-white, our 2D version of the game could greatly benefit from non-black colors being used for the non-white squares. Greys, blues, greens are all great choices — just don't go for a color that's particularly bright. We want the background to be just that: a background. For the chess pieces themselves: because there isn't a DrawChessPiece method available in Graphics, you'll need to hunt down some images of each piece you can harvest. You might need "_onWhite" and "_onBlack" versions of each piece as might be necessary, or convenient. Once you have the assets and the generalized method for placing each of them on an arbitary square, you're on solid ground.

As you might suspect, you'll want a 2D matrix in the background that dictates where all the pieces currently are, as well as empty spaces. Given the wide variety of values each square can take on (e.g. white pawn, black knight, white bishop, etc.), there's a motivation to use a more robust data type then we've used in class for TicTacToe, which was the Nullable<bool>. You could use strings or perhaps an enumerated type containing all the possible pieces. After every move, you'll likely Refresh your game board to reflect the change to positions.

Each player will take turns moving one of their chess pieces (first check). A mouse click should suffice for selecting one (or changing to a different piece that player controls), which will then be followed by another square you'd like to move that piece to (second check). You'll likely want to feature some kind of highlight of which piece you've selected, such as coloring the square that piece is on to be slightly different, just to keep track of what piece is trying to move where. Additionally, it would be helpful to color each of the squares this piece can possibly move to as well. Assuming the square you move this piece to is valid, you'll then want to (third) check whether the King becomes exposed as a result of this move. If the answer is yes, then the move is rejected.

It will be important to provide some feedback on rejected moves, such as producing a message somewhere with an error message. Such as, "This piece cannot reach that square" or "This move exposes the King to attack". While it should be relatively straight-forward to check of whether a Pawn can move to the square directly in front of it, the more expensive check will be the third one, in which you check if whether any of the existing enemy pieces can attack the King after any given change to the game board. Some of the checks are simpler than others — for Rook pieces, you only need to check whether the King piece and this Rook share a X or Y coordinate, followed by checking if there is an uninterrupted path between them.

You will need to detect (and announce somehow to the players) when a King is "checked". This is the game-state where the King could be attacked on the enemy's next turn, requiring the opposing player to move their King out of harm's way, block the incoming attack, or remove the attacking piece from the board. When a "checkmate" has been reached, you should display a "Surrender" button after the players have gotten a chance to validate the finale of the game.

Clicking the "Surrender" button should result in a kind of summary of the game played. How many pieces each player lost, how many moves were made, and how long the game lasted. Speaking of which: you should have a timer that counts up from 0:00 to some MM:SS value when the game concludes, displayed alongside your game board. As well as a persistent display of who's turn it currently is. Bonus Cool Person Points if you highlight this display to match the text and color of the player who's turn it is.

Have fun!