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.
๐จ 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.
C++17 compatible compiler (g++, clang, MSVC)
SFML 2.5+ graphics library
A TrueType font file (e.g., arial.ttf)
Installation & Compilation
- 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).
-
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.
-
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.