Skip to content

MuhammadUmar1204/Chess-in-Cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Chess-in-C++

A C++ chess game with SFML graphics, local multiplayer & AI opponent. Features full chess logic, mouse control, Unicode piece symbols, turn/check display, and instant restart. Ready to compile with SFML 2.5+. Chess โ€“ Advanced Graphics, Multiplayer & AI A complete C++ chess game with SFML graphics, local multiplayer, and AI opponent. Features full chess rules (excluding castling/en passant), smooth mouse-driven interface, and Unicode piece symbols.

Features

๐ŸŽจ Advanced graphics โ€“ custom board colors, piece highlights, and Unicode chess symbols.

๐Ÿ‘ฅ Two game modes โ€“ Human vs Human or Human vs AI (AI plays random legal moves).

โ™Ÿ๏ธ Full chess logic โ€“ all pieces move correctly, check detection, pawn promotion, checkmate/stalemate.

๐Ÿ–ฑ๏ธ Mouse-controlled โ€“ click to select a piece, click again to move.

๐ŸŽฎ Easy restart โ€“ press R to reset the game at any time.

Requirements

C++17 compatible compiler (g++, clang, MSVC)

SFML 2.5+ graphics library

A TrueType font file (e.g., arial.ttf)

Installation & Compilation

  1. Install SFML Linux (Ubuntu/Debian) bash sudo apt update sudo apt install libsfml-dev macOS (Homebrew) bash brew install sfml Windows (MinGW) Download the latest SFML release for MinGW from sfml-dev.org.

Extract the archive to a folder, e.g., C:\SFML.

Add the include and lib paths to your compiler (see compilation instructions).

  1. Get the Font Download any TrueType font (e.g., from Google Fonts) and place it in the same folder as the source code. Rename it to arial.ttf or modify the code to match your font filename.

  2. Compile the Code Save the provided C++ code as chess.cpp.

Linux / macOS bash g++ -std=c++17 chess.cpp -o chess -lsfml-graphics -lsfml-window -lsfml-system Windows (MinGW) bash g++ -std=c++17 chess.cpp -o chess.exe -IC:\SFML\include -LC:\SFML\lib -lsfml-graphics -lsfml-window -lsfml-system After compilation, copy the SFML DLLs from C:\SFML\bin to the same folder as chess.exe.

Running the Game Run the executable:

Linux/macOS: ./chess

Windows: chess.exe

A menu appears:

Press 1 for Human vs Human.

Press 2 for Human vs AI (AI plays black).

Gameplay:

Click on a piece to select it (highlighted in yellow).

Click on a valid square to move.

The game shows turn status and check warnings at the top.

Press R to restart at any time.

Code Structure Piece โ€“ struct representing a chess piece (type, color, moved flag).

Board โ€“ core logic: move validation, check detection, game state.

AI โ€“ simple random move generator.

ChessGUI โ€“ SFML rendering, event handling, game loop.

Limitations & Future Improvements โŒ Castling and en passant are not implemented (easy to add).

โŒ AI is random โ€“ could be upgraded with minimax and evaluation.

โŒ No network multiplayer โ€“ can be added using SFML networking.

โŒ No move animations โ€“ but can be implemented with smooth transitions.

Feel free to extend and contribute!

License This project is open source under the MIT License.

About

A C++ chess game with SFML graphics, local multiplayer & AI opponent. Features full chess logic, mouse control, Unicode piece symbols, turn/check display, and instant restart. Ready to compile with SFML 2.5+.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages