Tetris on the SugarCraft stack
SugarCraft runtime, SugarStyle for rounded borders + per-piece colours, deterministic 7-bag RNG, ghost piece, hard drop, hold, level-driven gravity ramp, NES-style line-clear scoring. Full SRS wall-kicks via official Tetris Association tables, T-Spin detection via the centre-diagonal 3-corner rule, Back-to-Back (1.5ร) and combo bonuses, and perfect-clear detection (+5000/level).
composer require sugarcraft/candy-tetris
# or run the shipped binary from a clone:
composer install
./candy-tetris/bin/candy-tetris # single player
./candy-tetris/bin/candy-tetris --vs # VS the computer
./bin/candy-tetris
# Controls
# โ / โ Move left / right
# โ / x Rotate clockwise
# z Rotate counter-cw
# โ Soft drop
# Space Hard drop
# c Hold piece
# p Pause / resume
# r Restart after game over
# q Quit
| Class | Method | Description |
|---|---|---|
| Tetromino | cases() / color() | Backed enum of the seven kinds; 256-colour code per kind |
| Piece | rotated(delta) / moved(dx, dy) | Immutable transforms (withX/withY for placement) |
| Piece | rotationsWithKicks(board, delta) | Candidate positions in SRS kick order (naive first) |
| Board | new(rows) | 10-wide grid (4 hidden + 20 visible rows; dims fixed) |
| Board | place(piece) | Lock a piece's cells into the grid |
| Board | fits(piece) / dropPiece(piece) | Legality gate and resting-position query |
| Board | clearLines() / isPerfectClear() | Clear completed rows; true iff the grid ends empty |
| Bag | next() | Returns [Tetromino, advanced Bag] โ value semantics |
| Bag | peek(n) | Pure preview; mutates nothing and consumes no draws |
| Score | withLines(count) | New Score: NES base ร (level+1), lines, level re-derived |
| Game | start() / update(msg) | TEA model: every message yields [Game, ?Cmd] |
| SrsKickTable | kicks(piece, from, to) | Return kick offsets for a rotation transition |
| SrsKickTable | allKicks(piece) | Return all transition tables for a piece |
| Scoring\TSpin | detect(board, piece, wasRotated) | Centre-diagonal 3-corner rule; returns TSpin(active, mini) |
| Scoring\TSpin | T_SPIN_POINTS / T_SPIN_MINI_POINTS | Base score constants (400 / 100, scaled by level+1) |
VHS-recorded GIFs of the shipped tapes. Regenerated automatically on every push that touches the source.