A lightweight C++17 Rock-Paper-Scissors game focused on clean architecture, safe input handling, and strict test coverage using GoogleTest.
- Game Flexibility: The player can configure the total number of rounds and can exit the game at any point during gameplay.
- User-Friendly Interface: Clear, readable terminal output shows current scores and round progress at each step.
- Move Generation Algorithm: Moves are generated using a Pseudo-Random Number Generator (PRNG) based on the Mersenne Twister algorithm (
std::mt19937seeded viastd::random_device) to ensure uniform move selection. - Decoupled Architecture: Core game logic (
evaluateResult,parseRoundSize,parsePlayerCommand) consists of pure, stateless functions completely isolated from standard terminal I/O, making unit testing straightforward. - Modern Error Handling: Uses
std::optionalto handle invalid inputs cleanly without relying on exceptions for control flow. - Efficient Input Validation: Uses
std::from_charsfor high-performance integer parsing without heap allocations or runtime exception overhead. - Strict Compiler Hygiene: Compiled with
-Wall -Wextra -Wpedantic -Werror(/W4 /WXon MSVC) to ensure the codebase remains completely warning-free.
.
├── CMakeLists.txt
├── include/
│ └── rock_paper_scissors.hpp
├── src/
│ ├── main.cpp
│ └── rock_paper_scissors.cpp
└── test/
└── test_main.cpp
- C++17 compatible compiler (Clang 10+, GCC 9+, or MSVC 2019+)
- CMake (version 3.14 or higher)
To configure and build both the main executable and the unit test suite:
#configure the build directory (automatically downloads GoogleTest)
cmake -B build
#compile all targets
cmake --build build
The GoogleTest suite verifies various move outcomes, string case insensitivity, blank or whitespace inputs, invalid inputs, and numerical overflow boundaries up to std::size_t limits.
#run unit tests directly
./build/test_runner#launch the terminal-based game
./build/rps_game- Author: Tonmoy Sharma
- Email: tonmoy2@icloud.com
- GitHub: github.com/tonmoySh