PHPackages                             sugarcraft/candy-tetris - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sugarcraft/candy-tetris

ActiveProject

sugarcraft/candy-tetris
=======================

Tetris clone built on the SugarCraft stack — SugarCraft runtime, CandySprinkles styling, HoneyBounce-driven smooth piece previews. Standard SRS rules (7-bag RNG, ghost piece, hard drop, hold, level/speed curve, line-clear scoring). A real demo of the runtime, not a toy.

10PHP

Since May 29Pushed 1w agoCompare

[ Source](https://github.com/sugarcraft/candy-tetris)[ Packagist](https://packagist.org/packages/sugarcraft/candy-tetris)[ RSS](/packages/sugarcraft-candy-tetris/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![candy-tetris](.assets/icon.png)](.assets/icon.png)

CandyTetris
===========

[](#candytetris)

[![CI](https://github.com/detain/sugarcraft/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/detain/sugarcraft/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/aea7bd9011c578cf8dfe3d5410c0fd1d97c15fdea37c630f0a50bbb1d95587b0/68747470733a2f2f636f6465636f762e696f2f67682f64657461696e2f737567617263726166742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f666c61673d63616e64792d746574726973)](https://app.codecov.io/gh/detain/sugarcraft?flags%5B0%5D=candy-tetris)[![Packagist Version](https://camo.githubusercontent.com/c94431de77f286f070e0c412d3bb1c1a6ea93bedd29522330e02ca3e1ab093ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737567617263726166742f63616e64792d7465747269733f6c6162656c3d7061636b6167697374)](https://packagist.org/packages/sugarcraft/candy-tetris)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP](https://camo.githubusercontent.com/e78ffc83837c0d12647811a7fd1910c3cbeae04988de94bb4fd5b67e0874696a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135382e312d3838393262662e737667)](https://www.php.net/)

[![demo](.vhs/play.gif)](.vhs/play.gif)

Tetris built on the SugarCraft stack. SugarCraft runtime, CandySprinkles for the rounded borders and per-piece colours, deterministic 7-bag RNG, ghost piece, hard drop, hold, level-driven gravity ramp, line-clear scoring.

Run it
------

[](#run-it)

```
composer install
./bin/tetris         # Single player mode
./bin/tetris -v      # VS Computer mode
./bin/tetris --vs    # VS Computer mode (long form)
```

VS Computer Mode
----------------

[](#vs-computer-mode)

Compete against an AI opponent in split-screen mode. When you clear lines, garbage rows are sent to the computer. When the computer clears lines, garbage rows are sent to you. Last player standing wins!

[![vs-computer demo](.vhs/vs-computer.gif)](.vhs/vs-computer.gif)

### VS Mode Controls

[](#vs-mode-controls)

KeyAction← / →Move left / right↑ / xRotate clockwisezRotate counter-cw↓Soft dropSpaceHard droppPause / resumeqQuitThe computer opponent uses weighted heuristics (board height, holes, gaps, lines) to make optimal moves.

Controls
--------

[](#controls)

KeyAction← / →Move left / right↑ / xRotate clockwisezRotate counter-cw↓Soft dropSpaceHard droppPause / resumeqQuitScoring
-------

[](#scoring)

### Line-clear scoring

[](#line-clear-scoring)

Lines clearedBase points × (level + 1)140210033004 (Tetris)1200Level rises every 10 lines. Gravity speeds up at every level — by level 9 pieces fall every 6 frames, by level 29+ they fall every frame. The frame-rate-agnostic `Score::framesPerRow()` is what the gravity tick consults.

### T-Spin scoring

[](#t-spin-scoring)

When a T piece is rotated into a position where two or more of its four diagonal corner cells are already filled (walls count as filled), it scores as a **T-Spin**:

TypeBase pointsT-Spin400 × (level + 1)T-Spin Mini100 × (level + 1)T-Spin Mini is detected when exactly two front corners are filled (the side the piece entered from).

**3-corner rule:** A T-Spin is active when the locked T piece's final position differs in rotation from its pre-lock rotation, AND at least two of the four diagonal corner cells around the T are occupied (wall/out-of-bounds = occupied). See `Scoring\TSpin::detect()`.

### Back-to-Back (B2B) bonus

[](#back-to-back-b2b-bonus)

Consecutive Tetris clears or full T-Spins (non-mini) carry a **1.5× multiplier** on the line-clear base points:

- 4-line Tetris after a prior Tetris → 1200 × 1.5 × (level + 1)
- Full T-Spin after a prior full T-Spin → 400 × 1.5 × (level + 1)

B2B resets when a 1–3 line clear or a T-Spin Mini breaks the streak.

### Combo bonus

[](#combo-bonus)

Consecutive line clears (regardless of type) build a **combo counter** — each combo step adds `combo × 10 × (level + 1)` bonus points. The counter resets to 0 on any clean (zero-line) piece placement.

### Perfect clear bonus

[](#perfect-clear-bonus)

When all lines are cleared at once and the board becomes completely empty, an additional **+5000 × (level + 1)** bonus is awarded.

### DAS / ARR keyboard timing

[](#das--arr-keyboard-timing)

Horizontal movement uses **Delayed Auto Shift (DAS)** and **Auto Repeat Rate (ARR)** for precise key repeat:

ParameterDefaultDescriptionDAS delay167 msTime a direction key must be held before auto-repeat beginsARR interval50 msInterval between repeated actions once DAS threshold is passedThis gives precise single-tap control (release before DAS) and smooth continuous movement (hold past DAS threshold). Defaults can be overridden via `Das::create($dasMicroseconds, $arrMicroseconds)`. See `Input\Das`.

Architecture
------------

[](#architecture)

Nine pure-state classes, each individually testable without booting the runtime:

```
Tetromino    enum   ─►  shape data + colour for each of the 7 pieces
Piece        VO     ─►  Tetromino + rotation + (x, y), with immutable transforms
Board        VO     ─►  10×24 grid (4 hidden rows above), fits/place/clearLines/dropPiece
Bag          ──►    7-bag RNG with peek(); injectable RNG closure for deterministic tests
Score        VO     ─►  points / lines / level + level-driven gravity interval
Game         Model  ─►  SugarCraft Model orchestrating the above + key handling
Computer     ──►    AI opponent with board-evaluation heuristics
VsGame       Model  ─►  VS mode combining two Games with garbage row passing
Renderer     ──►    pure view function from Game to frame string
VsRenderer   ──►    split-screen view for VS mode

```

Why so split? Because each piece is testable in isolation — line-clear correctness has nothing to do with rotation correctness has nothing to do with score arithmetic. The full test suite is **82 tests, 1669 assertions** and runs in ~300 ms; the deterministic RNG injection means even the `Game` integration tests are reproducible across runs.

Super Rotation System
---------------------

[](#super-rotation-system)

candy-tetris implements the official Tetris Association **Super Rotation System (SRS)** — the same system used in modern Tetris games. When a piece rotation would collide with a wall or occupied cell, SRS tries a series of offset candidates before giving up:

Piece typeOffsets tried per rotationJ / L / S / T / Z5 candidates per transitionI5 candidates (larger offsets)ONo kicks (always valid)The tables are from the [official SRS specification](https://tetris.fandom.com/wiki/SRS). `Piece::rotationsWithKicks()` returns all candidates in order; the `Game` loop tests each for board validity and uses the first fit.

```
// All valid rotated positions (naive + wall-kick offsets)
$candidates = $piece->rotationsWithKicks(+1); // clockwise
foreach ($candidates as $candidate) {
    if ($board->fits($candidate)) {
        $piece = $candidate;
        break;
    }
}
```

Architecture
------------

[](#architecture-1)

Nine pure-state classes + one rotation table, each individually testable without booting the runtime:

```
Tetromino    enum   ─►  shape data + colour for each of the 7 pieces
Piece        VO     ─►  Tetromino + rotation + (x, y), with immutable transforms
Board        VO     ─►  10×24 grid (4 hidden rows above), fits/place/clearLines/dropPiece
Bag          ──►    7-bag RNG with peek(); injectable RNG closure for deterministic tests
Score        VO     ─►  points / lines / level + level-driven gravity interval
Game         Model  ─►  SugarCraft Model orchestrating the above + key handling
Computer     ──►    AI opponent with board-evaluation heuristics
VsGame       Model  ─►  VS mode combining two Games with garbage row passing
Renderer     ──►    pure view function from Game to frame string
VsRenderer   ──►    split-screen view for VS mode
Rotation/
  SrsKickTable  ──►  official SRS kick-offset tables (J/L/S/T/Z + I piece)

```

Shared foundations
------------------

[](#shared-foundations)

All game renderers build their playfield and score panel via [candy-buffer](https://github.com/detain/sugarcraft/tree/master/candy-buffer). The 10×20 playfield is a canonical `Buffer` cell grid; per-tetromino background style and ghost-piece foreground style are applied per-cell. `Buffer::withRegion` composites the score panel over the playfield interior. Snapshot tests via [candy-testing](https://github.com/detain/sugarcraft/tree/master/candy-testing) pin canonical game states (starting board, T-spin completion, pause overlay).

###  Health Score

21

↑

LowBetter than 18% of packages

Maintenance64

Regular maintenance activity

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 98.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1036e0717211b8030b83cbe729e8ba6ba442fdbd5285fb97a39d7dcfe339342?d=identicon)[detain](/maintainers/detain)

---

Top Contributors

[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (76 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

7-bag-rngarcadecandycoreclassic-gamedemoexamplegameghost-piecehard-drophold-piecelevelsmultiplayer-stylenes-scoringpuzzlesrssrs-tgmterminal-gametetristetris-gametui

### Embed Badge

![Health badge](/badges/sugarcraft-candy-tetris/health.svg)

```
[![Health](https://phpackages.com/badges/sugarcraft-candy-tetris/health.svg)](https://phpackages.com/packages/sugarcraft-candy-tetris)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
