ADdA_2048 is a terminal-based implementation of the classic 2048 sliding-tile puzzle game, written in Ada and designed with formal verification in mind using SPARK/GNATprove.
- Alire:
2.0.2 - Selected Alire toolchain:
gnat_native 14.2.1(default)gprbuild 22.0.1(default)
- Dependency crate:
gnatprove 14.1.1(fromalire.toml)
alr toolchain
alr --version
alr build
alr run
Project proof defaults are in adda_2048.gpr:
--mode=prove--level=2--prover=all--timeout=60
alr exec -- gnatprove -P adda_2048.gpr📄 Proof output:
obj/development/gnatprove/gnatprove.out
Build:
docker build -t adda_2048 .Run:
docker run --rm -it adda_2048Run proof in container:
docker run --rm -it adda_2048 alr exec -- gnatprove -P adda_2048.gpr- The game is played on a square board (default size is 4x4).
- At the start of the game, 2 tiles spawn that each hold either a 2 or a 4.
- Combine equal tiles by moving in one direction; merged tiles add to score.
- After each valid move, a new tile (2 or 4) appears.
- The probability of spawning a 2 is 90% (a 4 spawns with a probability of 10%).
- You win when a tile reaches 2048 (you may continue for a higher score).
- The game ends when no moves are possible.
W/A/S/D: moveU: undoY: redoR: restartC: continue after hitting 2048Q: quit
- Only the first character from each input line is used.
- Extra characters are ignored with a warning.
src/main.adb: entry pointsrc/logic/: game logic, history, random tiles, high score, command handlingsrc/tui/: terminal menu, input, displaysrc/types/: core game types and invariantssrc/verification/: ghost helpers used by contracts/proofsconfig/: Alire-generated project configuration
- Some units are intentionally
SPARK_Mode => Off(I/O, randomness, file persistence paths). - In Docker,
.highscoreis ephemeral unless mounted from host storage.
- Variable board sizes (
4x4to8x8) selected at startup. - Undo/redo history (
U/Y) with bounded stack. - High-score tracking per board size, persisted to
.highscore. - SPARK-oriented contracts in game/types/history code.
- Ghost helpers for proof in
src/verification/verification-game_ghost.*andsrc/logic/logic-history.ads.
- SPARK proof excludes I/O and randomness-related units (marked
SPARK_Mode => Off). - In Docker, high scores are not persisted across sessions by default (use a bind mount to keep
.highscore).