Skip to content

About

Falling-block puzzle in the browser with a tunable AI that stacks and clears lines for you. Zero dependencies, vanilla JS.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Auto-Blocks: a falling-block puzzle in your browser, with an AI that plays it for you

Auto-Blocks

A falling-block puzzle in the browser with a tunable AI that stacks and clears lines for you.

Play Now

Play online: https://mrdadado.github.io/Auto-Blocks/

License: Unlicense Zero dependencies Vanilla JS GitHub stars

The AI playing on autopilot

The AI playing on autopilot (default settings, real time)

A dependency-free falling-block puzzle game with a built-in AI that can play for you or show you where to put the current piece. Just open the page and hit AI Autoplay.

If you find this project fun or useful, please consider giving it a ⭐ — it really helps!

Features

  • Falling-block gameplay on a 10×20 board: seven four-cell pieces, a Hold slot, a three-piece Next queue, a landing shadow, and speed that goes up every 10 lines
  • Keyboard and touch controls: ← → move, ↑ / X rotate, Z rotate the other way, ↓ soft drop, Space hard drop, C hold, P pause, F2 new game; on-screen buttons on mobile
  • AI Autoplay: watch the AI rotate, shift and drop every piece, at any speed from step-by-step to hundreds of pieces per second
  • Hint: highlights where the AI would put the current piece (or tells you to hold first)
  • Tunable AI: lookahead depth, whether it may use Hold, and the four heuristic weights
  • Light and dark themes: follows your system setting, with a toggle that is remembered across all Auto Games
  • Auto restart when the AI tops out, and a saved best score
  • Multilingual UI: English, 繁體中文, 简体中文, 日本語, 한국어 (auto-detected from the browser, selection remembered)
  • Settings, theme and best score saved in localStorage

Getting Started

No build step or dependencies are required.

  1. Clone the repository:
    git clone https://github.com/MrDaDaDo/Auto-Blocks.git
  2. Open index.html in a modern browser.

How the AI Works

For the current piece, the AI lists every spot it can actually reach: it rotates the piece at the top, slides it left and right until something blocks it, and drops it straight down. Each resulting board gets a score:

score = lines × cleared lines
      − height × sum of all column heights
      − holes × empty cells that have a block above them
      − bumpiness × sum of height differences between neighbouring columns
Setting Default Meaning
Lookahead 2 How many pieces are planned together: the current one plus pieces from the Next queue
Height weight 51 Penalty for a tall stack
Lines weight 76 Reward for each cleared line
Holes weight 36 Penalty for each covered empty cell
Bumpiness weight 18 Penalty for an uneven surface
AI uses Hold on Also try the held piece (or the next one, if Hold is empty) and keep whichever is better

With a lookahead above 1, the AI places the following pieces the same way and judges a spot by the best board it can lead to. To keep that fast, only the 6 best boards at each step are expanded further. The AI only looks at the three pieces shown in the Next queue; it never peeks further.

The default weights are the well-known four-feature set found by Yiyuan Lee with a genetic algorithm (see Tetris AI – The (Near) Perfect Bot).

While the AI plays, pieces do not fall on their own; the Delay per action setting sets the pace.

The dark theme, with a hint highlighted on the board

How well it plays

Simulated in Node.js with the default weights, each game stopped at a fixed number of pieces:

Lookahead Hold Games Result Time per piece
1 off 10 Topped out after 1,434 to 10,931 pieces 0.02 ms
1 on 10 All reached the 20,000-piece limit (about 8,000 lines each) 0.04 ms
2 on 5 All reached the 20,000-piece limit 1.2 ms
3 on 3 All reached the 5,000-piece limit 8.3 ms

So with Hold enabled the AI did not lose a single test game; how long it could keep going beyond those limits was not measured.

Project Structure

index.html   Page layout and styles (light and dark themes)
game.js      Game logic, rendering, input, theme and AI controls
ai.js        Piece rules (shapes, rotation, collision) and the placement-search AI
i18n.js      Translations and language switching

More Auto Games

Play them all at https://mrdadado.github.io/

License

Released into the public domain under The Unlicense.

About

Falling-block puzzle in the browser with a tunable AI that stacks and clears lines for you. Zero dependencies, vanilla JS.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages