Artificial Intelligence 10 min read

Design and Implementation of a High‑Scoring Tetris AI for the Tencent Geek Challenge

Zheng Lin‑kai’s record‑breaking Tetris AI for the Tencent Geek Challenge combines a two‑layer breadth‑first search—stage‑level pruning in Python and fast round‑level BFS in C++—with a heuristic that rewards high score, low occupied cells, and smooth board transitions, enabling a 1,413,876‑point performance.

Tencent Cloud Developer
Tencent Cloud Developer
Tencent Cloud Developer
Design and Implementation of a High‑Scoring Tetris AI for the Tencent Geek Challenge

The Tencent Cloud+ Community, together with Tencent Maker and the Security Platform, organized the innovative competition "Tencent Geek Challenge – Goose Russian Block". Over 4,500 participants submitted diverse projects, and the champion was Zheng Lin‑kai, a Tsinghua University computer science student specializing in Web security.

Zheng achieved a record score of 1,413,876 in the external track, the highest score across both internal and external tracks. He shares the technical details of his solution, which differs significantly from typical Tetris AI approaches.

Problem Description

The task is a Web‑based Tetris variant where 10,000 pieces fall before the game ends. The piece drop sequence is generated by a fixed‑seed pseudo‑random number generator, making the order deterministic. Piece probabilities are altered: the I‑piece appears with probability 2/29, while the S and Z pieces appear with probability 6/29 each, increasing difficulty. Scoring is also modified – clearing more rows at once yields disproportionately higher points.

Why Traditional AI Is Insufficient

Most Tetris AIs aim merely to survive (avoid "death"). Zheng observed that survival alone caps the score around 100 k, far below the competition’s top scores (≈1.37 M). Therefore, the evaluation function must reward both high score and board compactness, while handling the contradictory effects of line clears (score ↑, occupied cells ↓).

Two‑Layer Search Framework

He introduced a staged breadth‑first search (BFS) with aggressive pruning based on a heuristic evaluation:

Stage definition: The sequence of moves between two line‑clear events.

First layer (stage‑level): Expands the game state once per stage. It uses a bucket structure of size 10,000 × 200 (round × occupied‑cell count). Each bucket holds a priority queue of the top 10 states.

Second layer (round‑level): Performs a simple BFS from a given state until a line clear occurs, generating all possible stage outcomes. The leaf nodes (states after a line clear) are fed back to the first layer.

This design keeps the total number of explored states manageable while allowing deep look‑ahead when needed.

Heuristic Evaluation

The evaluation combines three metrics:

Current score (higher is better).

Number of occupied cells (fewer is better).

Board transitions – the sum of row and column transitions, reflecting board smoothness.

The transition metric is computed by counting changes from empty to filled and vice‑versa across rows and columns.

// Return the number of occupied cells on the board inline int getGrids() { boradGrids = 0; for (int y = 1; y <= LIMITHEIGHT; y++) boradGrids += bit(gridInfo[nowGame][y]) - 2; return boradGrids; } // Return the number of vertical transitions (fewer means a flatter board) inline int getTransitions(bool recount = true) { if (recount) // recompute the value { boardRowTransitions = 0; boardColTransitions = 0; for (int y = 1; y <= LIMITHEIGHT; y++) boardRowTransitions += bit(gridInfo[nowGame][y] ^ (gridInfo[nowGame][y] >> 1)) - 1, // row transitions sum boardColTransitions += bit(gridInfo[nowGame][y] ^ gridInfo[nowGame][y - 1]); // column transitions sum } return boardRowTransitions + boardColTransitions; }

Implementation Details

The first‑layer search is written in Python for rapid prototyping, while the second‑layer, performance‑critical BFS is implemented in C++. This hybrid approach leverages Python’s flexibility and C++’s speed.

The complete source code is available on GitHub (https://github.com/Konano/geekTencent-4-Tetris) with extensive comments.

Conclusion

By redefining the search granularity, employing a two‑layer architecture, and designing a heuristic that balances score and board smoothness, Zheng’s AI achieved a record‑breaking score. The report demonstrates how algorithmic creativity and careful engineering can push the limits of game‑AI performance.

PythonCgame AIHeuristic EvaluationMonte Carlo Tree SearchTetris AITwo‑Layer Search
Tencent Cloud Developer
Written by

Tencent Cloud Developer

Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.