This is the final project for the C++ Workshops. The idea is to create a chess game.
You can look up the rules online, so the rules are briefly outlined here.
There are six types of pieces
- King moves 1 step in any direction
- Queen moves in any direction any distance, unless blocked by another piece
- Bishop moves along the diagonals any distance, unless blocked by another piece
- Rook moves vertically and horizontally any distance, unless blocked by another piece
- Knight moves in an L shape, can "jump" over pieces
- Pawn moves forward 1 step (or 2 on the first move), unless blocked by another piece
A piece takes another piece by moving to the location occupied by that piece. If a piece is able to take another piece, then we say it places that piece under attack.
- A piece can only take a piece of the opposite colour
- The piece that is taken is permanently removed from the board
The aim of the game is to place the opponent's King under attack such that the opponent cannot escape in one move. This is known as checkmate. Simply placing the King under attack whether escape is possible or not is known as check.
There are additional rules that govern piece movement:
- Pawn is the only piece whose standard move is different from its taking move. Pawns take diagonally.
- If there are no legal moves but your King is not in check, then that is a stalemate and the game is a draw
- If your King is currently in check, a move must take it out of check to be legal
- If your King is not in check, a move is not legal if it puts your King in check
That is, it's not legal to make a move such that after the move is completed, your King is in check.
We've provided some starter code for dealing with the GUI and taking in user input, so when the game first runs
- The board initializes with the pieces of each side in their correct locations
- These pieces are displayed on the UI
- White player starts
Additionally we handle user input
- When a user clicks on a piece of their colour the legal moves for that piece are displayed
- If a legal move is clicked, tell the game to move the piece
- If a different piece is clicked, the legal moves of that piece is shown
- If any other click happens and a piece was selected, then the piece is deselected
- When a move happens, the turn switches to the opposite player
- Determining if King is in check for each colour
- Determining if the game is in stalemate
- Determining if the game is in checkmate
- Windows 64bit with MingW
- MacOS
For Windows if you followed the set up from the first workshop, you should have MingW. If your system is supported, cloning the repository should be sufficient and no additional setup is required. Otherwise, continue reading.
- Linux
- Windows not MingW (Cygwin, MSYS, etc)
- Windows 32bit with MingW
If your system is not supported then you need to install SDL2 on your own.
-
Follow this set up guide: https://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php
-
Update the makefile for your OS so that the
INCLUDE_PATHS
andLIBRARY_PATHS
point to where you downloaded SDL2. (If you're on Linux good luck, we do not have a Linux Makefile).
In the chess
directory run the command
Unix:
make
Followed by
./Chess
Windows:
mingw32-make.exe
Followed by
.\Chess.exe
- On Windows there is no MAKE
- On Mac I get the error
fatal error: 'SDL.h' file not found
- Every
#include <SDL.h>
needs to be replaced with#include <SDL2/SDL.h>
- Every
#include <SDL_image.h>
needs to be replaced with#include <SDL2_image/SDL_image.h>
- These are in
ChessTexture.cpp
,ChessGraphicsSystem.cpp
, andChessGraphicsSystem.hpp
- Every