C++ puzzle game on a 3×3 grid — select cells to increment rows and columns until all values equal 9. Supports unlimited undo, redo, and hints.
The game initialises a 3×3 grid of 9s and applies random decrementing moves at a chosen difficulty level. The player then selects cells to apply incrementing moves, aiming to restore every cell to 9. Every move is captured in a linked stack, enabling full undo/redo history. A hint engine evaluates all possible next moves and suggests the one that brings the grid closest to solved.
targetNumberGame/
├── include/
│ ├── Stack.h # Stack class — linked-list undo/redo storage
│ └── Game.h # MoveHandler class — game state and move logic
├── src/
│ ├── stack.cpp # Stack implementation
│ ├── game.cpp # MoveHandler implementation
│ └── main.cpp # CLI entry point
├── tests/
│ └── test_game.cpp # Standalone test program (no framework needed)
└── CMakeLists.txt
- Memento — each
Stack::push()captures a full grid snapshot;undo()/redo()restore them without exposing internal state - Command —
applyMove(),undo(), andredo()encapsulate reversible operations that operate on the same grid state - Single Responsibility —
Stackhandles only memory management;MoveHandlerhandles only game rules
- C++17
- Standard Library only —
<iostream>,<iomanip>,<new>,<cstdlib> - CMake 3.14+ — cross-platform build system
git clone https://github.com/DaoudSabat/targetNumberGame.git
cd targetNumberGame
cmake -B build && cmake --build build
./build/target_gameOr open targetNumberGame.sln in Visual Studio.
Enter difficulty level (1-9): 3
Current Grid:
0 1 2
0 8 9 8
1 9 8 9
2 8 9 8
Options:
1) Play move 2) Undo 3) Redo 4) Show hint 5) Exit
cmake --build build --target test_game
./build/test_gameRunning targetNumberGame tests...
PASS: Stack push/pop round-trip
PASS: Stack underflow returns error code
PASS: New stack is empty
PASS: Difficulty-0 game starts solved
PASS: applyMove changes grid state
PASS: undo restores previous state
All tests passed.
MIT