r2048 is a terminal version of the classic 2048 game, built in Rust using the ratatui crate for the UI design.
←
/→
– Browse your options like a proE
– Dive into the actionQ
orEsc
– Exit the game gracefully
↑
/↓
/←
/→
– Slide those tiles with precisionQ
orEsc
– Takes you back to the menu when things get toughCtrl + C
– Nuclear option (closes everything immediately)
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.
-
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.
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
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
There are some potential issues with
cargo install
if you are on Windows
stdarg.h
missing → install C++ build tools + Windows SDKlibsqlite3-sys
fails → MSVC headers required