akioi backend
Project description
akioi-2048 (Python)
Python package for a 2048 variant with multiplier tiles and score tracking.
Features
- Classic 2048 mechanics on a 4×4 board
- Multiplier tiles: -1 (×1), -2 (×2), -4 (×4)
- Simple functional API (
init,step) for simulations/AI - Detects victory (65536 tile) and game over
Install
pip install akioi-2048
Supports Python 3.8–3.13.
Quick Start
import akioi_2048 as ak
board = ak.init() # 4x4 board with two starting tiles
next_board, delta, state = ak.step(board, ak.Direction.Down)
print("delta=", delta)
print("state=", state)
print("next=", next_board)
Usage
- Import enums from the package and drive the game with a simple loop.
stepreturns the next board, the score delta for that move, and the current state.
import random
import akioi_2048 as ak
def pretty(board: list[list[int]]) -> str:
return "\n".join("\t".join(f"{v:>5}" for v in row) for row in board)
board = ak.init()
total = 0
while True:
# pick a random direction (replace with your policy/AI)
direction = random.choice([
ak.Direction.Up, ak.Direction.Down,
ak.Direction.Left, ak.Direction.Right,
])
board, delta, state = ak.step(board, direction)
total += delta
print(f"move={direction.name:>5} delta={delta:>6} total={total:>7}")
print(pretty(board), "\n")
if state is ak.State.Victory:
print("You win!")
break
if state is ak.State.GameOver:
print("Game over.")
break
Notes:
- Spawns are random after valid moves; runs are non-deterministic by design.
- Directions must be
ak.Direction.{Up,Down,Left,Right}; states areak.State.{Victory,GameOver,Continue}.
API
-
init() -> list[list[int]]- Create a new board with two starting tiles.
-
step(board: list[list[int]], direction: Direction) -> tuple[list[list[int]], int, State]- Apply one move. If the board changes, a new tile appears in a random empty cell.
- Returns
(new_board, delta_score, state)withstatein{State.Victory, State.GameOver, State.Continue}. directionmust beak.Direction.{Up,Down,Left,Right}.
Tiles and Scoring
- Positive numbers are normal tiles (2, 4, 8, …).
- Merging equal positives adds them; score increases by the merged value.
- Two 65536 tiles do not merge.
- Negative numbers are multipliers:
-1= ×1,-2= ×2,-4= ×4.-1 + -1 -> -2(score −2)-2 + -2 -> -4(score −4)-4tiles cannot merge further
- Number × Multiplier merges produce a number: e.g.
512 + -2 -> 1024(score +1024)- Constraint: they must be adjacent in the move direction, and the lower/forward tile must have no empty cells beyond it (per rules).
Spawning
A new tile spawns after a valid move with probabilities: 2, 4, -1, -2.
Two tiles spawn at game start.
States
- Victory: a
65536tile exists - GameOver: no legal moves remain
- Continue: otherwise
Rules Reference
Detailed rules and examples live under rules/.
Development
Run tests locally (requires Python >=3.8):
uv venv .venv
source .venv/bin/activate
uv run maturin develop
uv run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file akioi_2048-0.5.1.tar.gz.
File metadata
- Download URL: akioi_2048-0.5.1.tar.gz
- Upload date:
- Size: 404.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97f06d78417d191263b1db978aec866b2adb29e2dabcdb0a2c1a22508316bd6c
|
|
| MD5 |
f574a6e3d618b91f88dbb995fd898952
|
|
| BLAKE2b-256 |
a667b7ecc70dfe961d846ad3491e775a71bec7261ef4755f2161b9b783b33a34
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-win_arm64.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-win_arm64.whl
- Upload date:
- Size: 110.0 kB
- Tags: CPython 3.8+, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
581578eac3ca48de5121c38e80eb61ebf9d467b045ba480e92ed6845fab343c1
|
|
| MD5 |
80ef820fa467befa5affc69d3c7a8d91
|
|
| BLAKE2b-256 |
14fb8ab9e45d537d7d00d00a5b8cea2c29ca396873a252d58861d5043a1d7f08
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 113.6 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a53546750919bb846144ab71102698709cea6f4b4d7f0d0c171572f3f02eddd
|
|
| MD5 |
780c0e55c44ed7f403cc702d09b41caf
|
|
| BLAKE2b-256 |
84acf047774eb92f7c58d6669f92fc0204604083481f0c6f04c363023f3e0dc7
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-win32.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-win32.whl
- Upload date:
- Size: 107.0 kB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
820500b2b99550314989af828d8e40a5d6920106fa84314aaebb6efd6fc5e8e3
|
|
| MD5 |
b2bca76ba01aee32e2b7893c434a6a1a
|
|
| BLAKE2b-256 |
1789962872c700cad06c026acba17252f04ece73ece0080cf7291a6856dd3305
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 327.7 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94fc09dcd6a1241445b49a2965a34375e3ff37814eb37d84e9c01a243d32b666
|
|
| MD5 |
ee4ad8ee07b8912d239f61dd09068472
|
|
| BLAKE2b-256 |
4da5e3debedc91ef31fb59647a10951096e581796316a23493a0deb70317c2fc
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 309.5 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8560ca1b7ae4558e43265690cfdc85922979e2df81c7e31a9801472e00155df
|
|
| MD5 |
eab04b495330e7c4938e0e628375c38b
|
|
| BLAKE2b-256 |
5afaa1fedfc57570076283c8ab325af367797fb27c835ee7480db93e09bdd3a2
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 249.7 kB
- Tags: CPython 3.8+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f581425cdb8c463e6856602ee75e9e50771066c53992b7daeaecd95694c8a542
|
|
| MD5 |
13b3a24947da99505459d31369de80f5
|
|
| BLAKE2b-256 |
70d5326293f3f9ca3557a872f3cadcea40bb7f9f29ac5c844eb93e241fbe3f79
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 246.7 kB
- Tags: CPython 3.8+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b533e0fda1bd9ad8d93967357dcddbf4a81c0edcb27beb78dff48b06ed2363d
|
|
| MD5 |
a3da111f572b0c55a14c29390c9cda75
|
|
| BLAKE2b-256 |
6bdef255376fced317ed5bf0223caa4dcc2a404b88dd5e780ea70d7c41370abc
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 217.9 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e47c5f585f9f6e71bdf0f28caa429c4d532c173cb50c0e8a866bd7d5330669c
|
|
| MD5 |
25f173719550d9933f0705d925ef6f99
|
|
| BLAKE2b-256 |
26757916053b40f981072f1b0d4115f937e329fbb47b4b2556a868b4bec46a89
|
File details
Details for the file akioi_2048-0.5.1-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: akioi_2048-0.5.1-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 223.5 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71c2f2fd83c53ce069ccbbe11b906548aa0427f68b7ce41812c0fded633cd7be
|
|
| MD5 |
196cc89c29882f752160bc3d1bcf1796
|
|
| BLAKE2b-256 |
890179e0ce61b26087f3240e85bdea732963b2aff6d9e20139cd475c6077e092
|