4 releases
Uses new Rust 2024
| 0.1.3 | Sep 7, 2025 |
|---|---|
| 0.1.2 | Aug 30, 2025 |
| 0.1.1 | Aug 25, 2025 |
| 0.1.0 | Aug 25, 2025 |
#202 in Games
3.5MB
830 lines
r2048

r2048 is a terminal version of the classic 2048 game, built in Rust using the ratatui crate for the UI design.
Preview

Menu

Mid-game

ʕ·͡ᴥ·ʔ Winning ʕ·͡ᴥ·ʔ

ಡ_ಡ Losing ಡ_ಡ
Controls That Just Make Sense
Main Menu
←/→– Browse your options like a proE– Dive into the actionQorEsc– Exit the game gracefully
In the Game
↑/↓/←/→– Slide those tiles with precisionQorEsc– Takes you back to the menu when things get toughCtrl + C– Nuclear option (closes everything immediately)
Score Persistence
High scores now persist between sessions thanks to a built-in SQLite database.
Whether you quit the game, close your terminal, or reboot your machine, your top scores are safely stored — no setup required.
Each user has a separate score history, so you can challenge friends on the same machine without stepping on each other’s records. It’s simple, fast, and completely local.
Development Notes
-
C++ Background: Coming from C++, Rust’s borrow checker encouraged cleaner, safer code structure.
-
State Machine: Using enums and pattern matching, the game’s states (
Menu,Playing,Won,GameOver) are clear and type-safe. -
Game Logic: Implementing merge rules correctly without double merges was the trickiest part — it took several rewrites to get right.
ker encouraged -
Code Quality: Rust’s strictness helped catch subtle edge cases and improved overall code reliability.
Getting Started
1. Via crates.io:
If Rust is installed and you don't want to clone the repo, consider using cargo install
cargo install r2048
r2048
Note: Running the game this way will create a SQLite database in the folder where r2048 is executed to store high scores
2. Build it yourself
First, make sure you have Rust installed on your system. If not, grab it from rust-lang.org – it's surprisingly painless.
# Clone the repo
git clone https://github.com/asaft29/r2048.git
cd r2048
# Run it immediately with no verbose output showing (Cargo will handle the build)
cargo run --release
Warning
There are some potential issues with
cargo installif you are on Windows
stdarg.hmissing → install C++ build tools + Windows SDKlibsqlite3-sysfails → MSVC headers required
Dependencies
~32–47MB
~747K SLoC