scorpiox-bot-plugin-tetris-3d

scorpiox-bot-plugin-tetris-3d

main1 branch · 0 tags
VS Code
HTTPS
ForkDelete
Recent Commits
README

plugin_tetris_3d

A 3D block-stacking puzzle game for a SCORPIOX BOT node — a single clean-room C99

binary, MIT licensed, with no dependency beyond libc.

It serves a complete game UI: isometric cubes with real depth and shading,

ghost piece, next-piece preview, hold queue, keyboard and touch controls, and a

local high-score table. Everything is rendered by a small software 3D projector

onto a 2D canvas, so there is no WebGL requirement, no CDN script, and no

network request of any kind — the UI works on an offline node.

What it writes

One small JSON file, and nothing else:

<plugin dir>/.tetris_scores.json     {"scores":[1200,900,300]}

<plugin dir> is $BOT_PLUGIN_DIR when set, otherwise

%LOCALAPPDATA%\scorpiox\plugins on Windows and ~/.scorpiox/plugins

(/workspace/.scorpiox/plugins on BotCloud) on POSIX. SX_TETRIS_SCORES

overrides the full path, which is what the test suite uses.

The file holds the best ten scores, newest-best first. Writes are atomic at the

plugin level: the whole table is re-serialised on each accepted score, so a

truncated file can never leave a half-written entry.

Three modes

1. Discovery

./plugin_tetris_3d --meta
# {"name":"tetris","desc":"3D block game"}

SX_PLUGIN_META=1 does the same. This route stays unauthenticated so /plugins

discovery works.

2. JSON API

./plugin_tetris_3d '?action=scores'
./plugin_tetris_3d '?action=save_score&val=1200'
curl -d 'val=9900' 'http://node:8150/plugin_tetris_3d?action=save_score'
{"ok":true,"plugin":"plugin_tetris_3d","version":"1.0.0",
 "highscore":1200,"scores":[1200,900,300]}

action=scores (aliases highscore, leaderboard) reads the table.

action=save_score inserts a score and returns the updated table; a value that

is not a positive integer is refused with {"ok":false,"error":"invalid_score"}.

Any POST whose body carries val= or score= is treated as a save, and

?format=json returns the table. If the score file cannot be written the

response is {"ok":false,"error":"score_store_unwritable", ...} rather than a

silent success.

The API is gated by require_node_auth() exactly like every other node plugin:

X-Bot-Password, Authorization: Bearer <pwd>, or ?pwd= are all accepted, and

the process 401s only when BOT_PASSWORD is set and none of the three match.

--meta stays unauthenticated.

3. HTML UI

A GET without an action serves the game in a single self-contained document.

?embed=1 drops the outer chrome so it fits the Chat floating window; the layout

is fluid down to a 390 px viewport and short heights.

Controls:

Input Action
Left / Right or A / D move
Up or W / X rotate clockwise
Z rotate counter-clockwise
Down or S soft drop
Space hard drop
C hold
P / Esc pause
swipe left / right on the board move (touch)
tap the board rotate (touch)

Scoring is single 100, double 300, triple 500, tetris 800, multiplied by the

level; soft drop scores 1 per row and hard drop 2 per row. Level rises every ten

lines and the gravity interval tightens from 800 ms toward a 90 ms floor.

Screenshots

1440 1024 390
1440 1024 390

Light theme at 1024: light

Build

make            # native
make musl       # static musl x86_64, the universal Linux artifact
make arm64      # static aarch64
make win64      # static Win64 PE via MinGW-w64
make macos      # Apple clang, run this on macOS
make test       # build and run the offline assertion suite

On Windows:

powershell -ExecutionPolicy Bypass -File build.ps1

src/ui_html.h is generated from the single-file UI template and is committed,

so no generator step is needed to build.

Install on a node

make && make install PREFIX=$HOME/.scorpiox/plugins

Or through the node installer once published:

curl -X POST 'http://127.0.0.1:8150/plugin_manage?action=install' \
  -H "X-Bot-Password: $BOT_PASSWORD" \
  -d '{"slug":"tetris-3d","id":"plugin_tetris_3d","mode":"prebuilt","version":"1.0.0"}'

Tests

sh tests/run.sh          # 114 offline assertions, no network, no real score file
python3 tests/e2e.py     # Playwright: 1440 / 1024 / 390 viewports, dark + light

The offline suite covers metadata shape, the score store (ordering, the ten-entry

cap, unwritable store, percent-decoded and POST bodies), all three credential

forms, the full HTML contract, an emoji audit, and a full-git-history scan for

tokens and private addresses. The Playwright run asserts no horizontal or

vertical overflow at any viewport, that all three canvases have backing pixels

and actually painted, that the HUD renders, that a hard drop moves the score, and

that the touch pad is reachable at 390 px.

License

MIT. Copyright (c) 2026 SCORPIOX INC.