
Tetris
functional Tetris in Racket · big-bang
A fully playable Tetris, gravity, rotation, collision, line clears and scoring, built entirely from immutable state and pure functions in first-year CS.
Click the board, then: arrows move and soft-drop, Up rotates, Z rotates the other way, Space hard-drops, P pauses.
Press Start to play.
Center-pivot rotation and 10 times rows-squared scoring, the same rules as the Racket original, running live in the browser.
A browser reimplementation faithful to the Racket original: same 10 by 20 board, 0.3s gravity, center-pivot rotation and 10 times rows-squared scoring.
The source for this course project is kept private. Request access through the contact form and I will gladly share the code and walk through it.
Request accessTetris was the capstone build for Northeastern's CS2500 (Fundamentals of Computer Science 1), written in Racket using the 2htdp/universe big-bang framework and the design-recipe discipline the course teaches: structured data definitions (Brick, Piece, World), function wishlists, and a check-expect test for nearly every function. The whole game is modeled functionally. A World is an immutable record of the falling piece, the settled bricks and the score, and the engine threads it through pure handlers: a 0.3s gravity tick moves the active piece down one cell, key handlers move it left and right or rotate it counterclockwise and clockwise about its center, and a collision check rejects any move that would leave the 10 by 20 board or overlap a settled brick. When a piece locks, the board is scanned for any full 10-brick row, those rows are removed, everything above falls, and the score grows by 10 times the square of the number of rows cleared at once. The piece set covers the seven standard tetrominoes plus two course-specific bonus shapes, each spawned in one of seven random colors. The in-page demo is a faithful browser reimplementation of those exact mechanics.
- Racket
- 2htdp/universe
- Functional programming
- Design recipe
- Immutable state
- Collision detection
- Board
- 10 × 20 grid
- Pieces
- 7 tetrominoes + 2 bonus
- Line clear
- 10 × rows² points
- Source
- 1,128 LOC, Racket
What I'd improve
The whole board lives as a flat list of bricks that gets re-scanned and rebuilt every tick, which is clean to reason about but does redundant work; a fixed 2D grid would make collision and line detection cheaper and simpler. The course also pushed two non-standard bonus pieces and a rotation that pivots about a single brick, so spins near the wall can feel slightly off versus modern Tetris. With more time I would add wall-kick handling and a held-piece slot.