r2048 0.1.1

2048 written in rust
Documentation

r2048

Linux Build macOS Build Windows Build Crates.io

Preview

Controls That Just Make Sense

Main Menu

  • / – Browse your options like a pro
  • E – Dive into the action
  • Q or Esc – Exit the game gracefully

In the Game

  • / / / – Slide those tiles with precision
  • Q or Esc – Takes you back to the menu when things get tough
  • Ctrl + 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