๐งฉ A classic implementation of the ancient board game Three Men's Morris using C++ and the SFML graphics library. This is a two-player turn-based strategy game featuring placement, movement, and win detection via prime-number logic.
Note
This project was created as part of a University programming assignment.
When I started, I had no experience with SFML and only limited knowledge of C++ (and to be honest, I'm still learning!).
So the code might be a bit rough or unconventional in places.
If you spot anything that could be improved or have suggestions, feel free to open a pull request โ contributions are very welcome! ๐
- ๐ฎ Two-player local game (Player A vs Player B)
- ๐ง Efficient win detection using prime multiplication
- ๐งฉ Smooth transitions between game phases: Start, Placement, Movement, and Win
- ๐งผ Clean UI using custom textures and SFML
- ๐ฆ Logs game activity to
game.log - ๐ก Simple mouse-driven controls
- ๐จ Organized assets and modular code structure
To detect if a player has aligned 3 tokens in a winning pattern, this project uses unique prime numbers assigned to each board slot:
| 0 | 1 | 2 | --> | 13 | 03 | 23 |
| 3 | 4 | 5 | --> | 17 | 11 | 05 |
| 6 | 7 | 8 | --> | 29 | 07 | 19 |
- Each winning combination (row, column, or diagonal) has a unique product of its three primes.
- A player's placed token primes are multiplied together.
- If the player's total prime product is divisible by any winning combo product, they win.
โ This allows efficient win checking using basic arithmetic instead of nested loops or complex checks.
You can download a ready-to-run version of the game (including the required .dll files and assets) from the: โก๏ธ GitHub Releases Page ๐ฆ The ZIP archive includes:
- ThreeMensMorris.exe
- required .dll files
- assets/ folder (with images and UI textures) ๐ Just unzip and run .exe file!
- C++17 or later
- SFML 2.6+
git clone https://github.com/Sasivarnasarma/ThreeMensMorris
cd ThreeMensMorris
# Compile with g++ directly
g++ main.cpp icon.res -o ThreeMensMorris -lsfml-graphics -lsfml-window -lsfml-system -mwindowsOR Compile via Visual Studio or MinGW with SFML linked
- Place the compiled .exe file in the root project folder
- Make sure the following are in place:
- The assets/ folder (with all images, fonts, etc.) is in the same directory as the .exe
- All required .dll files (e.g., sfml-graphics.dll, sfml-window.dll, etc.) are also in the same directory as the .exe
Controls: Mouse-only interface.
Get three of your tokens in a row โ horizontally, vertically, or diagonally โ before your opponent does.
๐ข Phase 1: Placement
- Players take turns placing their 3 tokens on any empty circle on the board.
- Once all tokens are placed, the game transitions to the movement phase.
๐ Phase 2: Movement
- On your turn, select one of your tokens.
- Move it to an adjacent empty circle (no jumping allowed).
- Use strategy to block your opponent and align your own tokens.
- The first player to form a straight line of three tokens โ horizontally, vertically, or diagonally โ wins!
- C++ โ for implementing game logic, win detection, and event handling.
- SFML (Simple and Fast Multimedia Library) โ for graphics rendering, window control, and interaction.
- draw.io โ for planning UI layout, board design, and creating mockups
โค All design templates are included in theassets_drawio/folder.
This game was created as part of a university project, combining classic board game rules with modern graphics programming. The goal was to build a complete and playable graphical game using clean, efficient, and modular C++ code with SFML.
Contributions are welcome! If youโd like to:
- Add new features (AI opponent, sound effects, online multiplayer)
- Improve the UI or UX
- Fix bugs or optimize performance
- Improve documentation Feel free to fork the repo and open a pull request
If you find this project helpful or fun, please consider giving it a Star โญ on GitHub โ it really helps the project grow, reach more people, and motivates me to keep improving it!
This project is licensed under the MIT License.





