akioi-2048

Crates.ioakioi-2048
lib.rsakioi-2048
version0.5.0
created_at2025-09-13 10:53:01.86772+00
updated_at2025-09-13 11:30:00.481765+00
descriptionA 2048 engine with multiplier tiles
homepagehttps://github.com/jasonxue1/akioi-2048-rust
repository
max_upload_size
id1837539
size1,176,571
jasonxue (jasonxue1)

documentation

https://docs.rs/akioi-2048

README

akioi-2048

Pure Rust 2048 engine with multiplier tiles and score tracking.

Features

  • Classic 2048 mechanics
  • Special multiplier tiles: -1 (x1), -2 (x2), -4 (x4)
  • Simple functional API for simulations/AI
  • Detects victory (65536 tile) and game over

Rust API

init() -> [[i32; 4]; 4]

Create a new 4x4 board with two starting tiles.

step(board: [[i32; 4]; 4], dir: Direction) -> Result<([[i32; 4]; 4], i32, State), String>

  • Apply a move.
  • On success returns (new_board, delta_score, state)
  • state is an enum: State::{Victory, GameOver, Continue}.
  • Use Direction::{Up,Down,Left,Right} for dir.

Example

use akioi_2048::{init, step, Direction, State};

fn main() {
    let board = init();
    let (next, delta, state) = step(board, Direction::Down).unwrap();
    println!("delta={delta}, state={state:?}, next={next:?}");
}

Publishing

This library is intended to be published to crates.io. See .github/workflows/publish.yml.

Commit count: 0

cargo fmt