How to implement AI for Puyo Puyo game?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
An effective Puyo Puyo AI is mostly a search and evaluation problem. The game is small enough that you can simulate candidate placements directly, but rich enough that a good agent must think beyond the immediate clear and evaluate chain potential, board safety, and sometimes the opponent's threat level.
Represent the board and moves clearly
A standard Puyo Puyo board is 6 columns wide, and pieces arrive as colored pairs. The AI needs a state representation that supports:
- dropping a pair into any legal column and rotation
- applying gravity
- clearing groups of four or more connected colors
- resolving chain reactions until the board stabilizes
A simple board representation is a 2D array where each cell is empty or stores a color ID.
The key implementation detail is not the array itself. It is having a deterministic simulator for "apply move, resolve clears, return next board and score."
Generate all legal placements
For each falling pair, enumerate every legal placement:
- vertical orientation with first puyo on top
- vertical orientation reversed
- horizontal left-right
- horizontal right-left
Some placements are invalid near walls or when a column is full. The AI should generate only reachable placements under the actual game rules. Once you have that move list, the rest becomes a search problem.
Even a shallow search becomes effective once move generation and simulation are reliable.
Simulate chains exactly
Puyo Puyo strategy revolves around chain reactions, so the simulator must repeatedly:
- find connected groups of size at least four
- remove them
- apply gravity
- count chain depth and score
That loop is what turns a placement into a meaningful evaluation. If chain resolution is inaccurate, the AI will learn the wrong board values and choose bad setups.
A minimal skeleton looks like this:
Use heuristics before using deep learning
A strong hand-built AI can already be good. Start with an evaluation function that rewards:
- immediate score from clears
- future chain potential
- board compactness
- low column height
- few isolated single puyos
and penalizes:
- near-top danger
- messy color fragmentation
- moves that block future extensions
A simple evaluator might be:
This is not perfect, but it gives search something meaningful to optimize.
Add lookahead with beam search or minimax-style logic
For single-player planning, beam search or depth-limited search works well. For versus play, you may also model opponent pressure, garbage generation, and counterplay.
A practical starting point is:
- simulate all current-piece placements
- for each resulting board, simulate the next one or two incoming pairs
- keep only the best few boards at each depth
That beam-search style often gives a better tradeoff than exhaustive search because branching grows quickly in Puyo Puyo.
Common Pitfalls
The biggest mistake is focusing on neural networks too early while the simulator is still inaccurate. If move generation, gravity, or chain resolution are wrong, the AI cannot become good regardless of the learning method.
Another mistake is rewarding only immediate clears. Strong Puyo Puyo play often requires building larger future chains rather than greedily taking a small score now.
Developers also underestimate board safety. An evaluator that ignores stack height can produce flashy but suicidal moves.
Finally, do not start with opponent modeling before your single-board evaluation is solid. A bad heuristic does not improve just because the search tree gets larger.
Summary
- Puyo Puyo AI starts with reliable move generation and exact chain simulation.
- A good state evaluator should balance immediate clears, future chain potential, and board safety.
- Beam search or shallow lookahead is often a strong practical starting point.
- Accurate simulation matters more than sophisticated learning early on.
- Build the heuristic agent first, then add opponent modeling or machine learning if needed.
Related reading
- How to implement an image2D array sequence sliding window in tensorflow?
- How to implement CRF in tensorflow 2
- How to implement dropout in Pytorch, and where to apply it
- how to implement early stopping in tensorflow
- How to implement Grad-CAM on a trained network
- How to implement mini-batch gradient descent in python?
- How to implement multi-class semantic segmentation?
- How to implement neural network pruning?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.