Skip to content

LewisRye/chess

 
 

Repository files navigation

Chess Game

This is the final project for the C++ Workshops. The idea is to create a chess game.

The Rules of Chess

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.

Starter code

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
Screenshot 2023-11-30 at 4 10 02 PM Screenshot 2023-11-30 at 4 12 57 PM

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

Not implemented

  • Determining if King is in check for each colour
  • Determining if the game is in stalemate
  • Determining if the game is in checkmate

System Pre-requisites

Supported

  • 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.

Not supported

  • 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.

  1. Follow this set up guide: https://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php

  2. Update the makefile for your OS so that the INCLUDE_PATHS and LIBRARY_PATHS point to where you downloaded SDL2. (If you're on Linux good luck, we do not have a Linux Makefile).

Running the Game

In the chess directory run the command

Unix:

make

Followed by

./Chess

Windows:

mingw32-make.exe

Followed by

.\Chess.exe

Common Setup Errors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Languages

  • C 97.9%
  • C++ 1.0%
  • Objective-C 0.5%
  • CMake 0.4%
  • M4 0.2%
  • Shell 0.0%