This project implements a full-featured simulation of the strategic board game Coup, written in modern C++ using OOP principles, inheritance, and polymorphism. The game includes both game logic and a graphical user interface (GUI), as well as unit testing and memory validation via Valgrind.
All player actions (tax, gather, bribe, arrest, sanction, coup, invest) are implemented according to specified rules, with support for multiple roles and custom exception handling. The GUI is built using SFML and enables interactive gameplay.
Additionally, the game supports out-of-turn actions, such as Spy's peek_and_disable, Governor's undo_tax, Judge's undo_bribe, and General's undo_coup, which can be triggered via dedicated GUI buttons. Each of these actions can be used once per round per associated player.
.
├── assets/ # Fonts and resources for GUI
├── build/ # Output binaries (e.g., test_game, test_player)
├── include/
│ ├── gui/
│ │ └── GUI.hpp # GUI class definition
│ ├── roles/ # Header files for all special roles
│ │ ├── Baron.hpp
│ │ ├── General.hpp
│ │ ├── Governor.hpp
│ │ ├── Judge.hpp
│ │ ├── Merchant.hpp
│ │ └── Spy.hpp
│ ├── doctest.h # Testing framework
│ ├── Exceptions.hpp # All game-related exceptions
│ ├── Game.hpp # Core game logic interface
│ └── Player.hpp # Abstract base class for all players
│
├── src/
│ ├── gui/
│ │ ├── GUI.cpp # Main GUI implementation
│ │ ├── GUI_Draw.cpp # GUI rendering logic
│ │ ├── GUI_Events.cpp # Input event handling
│ │ └── GUI_Utils.cpp # Utility functions for GUI
│ ├── roles/
│ │ ├── Baron.cpp
│ │ ├── General.cpp
│ │ ├── Governor.cpp
│ │ ├── Judge.cpp
│ │ ├── Merchant.cpp
│ │ └── Spy.cpp
│ ├── Game.cpp
│ └── Player.cpp
│
├── tests/
│ ├── test_game.cpp # Covers Game class logic
│ ├── test_player.cpp # Covers Player class and behavior
│ └── test_roles.cpp # Covers all special roles
│
├── Main.cpp # GUI entry point
└── Makefile # Compilation rules and valgrind target
- Abstract Player class with overridable methods
- 6 unique roles: Governor, Spy, Judge, Baron, General, Merchant
- Undo mechanisms: Governor (undo tax), Judge (undo bribe), General (undo coup), Spy (disable arrest)
- Sanctions and Arrests: with full restrictions and rule enforcement
- GUI: Turn-based, visual role/action selection, SFML-based rendering
- Test suite with doctest
- Memory-safe: Fully validated using
valgrind
Unit tests are located in the tests/ folder:
test_game.cpp– coversGame.cpp(state transitions, turn logic, coup logic)test_player.cpp– coversPlayer.cppand core gameplay actionstest_roles.cpp– tests every special role’s behavior and edge cases
All tests are fully covered and Valgrind-clean.
The provided valgrind target in the Makefile only runs on test binaries, not on the GUI, to ensure accurate leak detection.
valgrind: build/test_game build/test_player build/test_roles
valgrind --leak-check=full --track-origins=yes ./build/test_game
valgrind --leak-check=full --track-origins=yes ./build/test_player
valgrind --leak-check=full --track-origins=yes ./build/test_rolesNote: We deliberately avoid running Valgrind on the
Main(GUI) executable because it pulls in system-level graphics and SFML libraries, which introduce unrelated memory traces and false positives. Only the test executables are covered since they include all logic without graphical side effects.
make # Builds all sources and test targetsmake Mainmake testmake valgrind- All classes are documented with
@briefusing Doxygen. - Code has been checked with
g++ -Wall -Wextra -pedantic -std=c++17.
This project is provided for academic purposes as part of a university assignment.
No redistribution or use in commercial products is allowed without explicit permission from the author.
- Email: neemanaviv@gmail.com