Skip to content

New: suggest a feature, report a bug or flag a wrong solution right here on the site. Send feedback

How ChromaOracle's Puzzle Solver Works: BFS Algorithm Explained

By ·

ChromaOracle finds the shortest solution to a color sort puzzle by using an algorithm called breadth-first search, or BFS. Instead of guessing or following heuristics, the solver systematically explores every possible sequence of moves, shortest sequences first, until it finds one that solves the puzzle. When the search finishes, the solution it returns uses the fewest moves possible under the solver's move rule, which is described below. Here is how it works, explained for both curious players and technically minded readers.

The Puzzle as a Search Problem

Every color sort puzzle — whether Water Sort, Ball Sort, or any variant — can be described as a search problem. The puzzle board at any moment is a "state": a specific arrangement of colors across all tubes. Each valid pour or move transforms one state into another. Solving the puzzle means finding a sequence of moves that transforms the starting state into the goal state, where every tube holds a single color or is empty.

Picture it as a map. Each intersection is a state. Each road between intersections is a move. The starting state is where you are now. The goal state is your destination. The solver's job is to find the shortest route.

What Counts as One Move

ChromaOracle uses one move rule for every variant. A move takes the whole run of matching color on top of a tube and puts it onto an empty tube or onto a tube whose top color matches. The move is allowed only when the destination has room for the whole run. Every tube holds exactly four items.

This is the Water Sort pour rule with one restriction: the solver never makes a partial pour, where only part of a run fits and the rest stays behind. Every step it shows is therefore a legal move in any color sort game. In games that move one ball, nut or hoop per tap, play a step that carries two or three items as that many taps from the same tube to the same destination.

The rule has two consequences. The solution has the fewest steps, which is not always the fewest single-item taps. And because the solver never considers partial pours or single-item moves, a game that allows them can occasionally clear a board in fewer moves, or clear a board the solver reports as unsolvable.

What Is Breadth-First Search?

Breadth-first search is a method for exploring this map of states in a very specific order: it checks all states that are one move away from the start, then all states that are two moves away, then three, and so on. It fans out evenly in all directions, layer by layer.

This layered approach is what guarantees optimality. Because BFS explores all five-move solutions before any six-move solution, the first time it reaches the goal state, it has necessarily found the shortest path. There is no shorter path it could have missed because it already checked every shorter possibility.

The process works like this:

  1. Start with the initial board state.
  2. Generate every valid move from that state. Each move produces a new board state.
  3. Check whether any of those new states is the solved state. If yes, return the move sequence.
  4. If not, add all the new states to a queue and repeat from step two with the next state in the queue.
  5. Continue until the goal is found or all reachable states have been explored.

If the queue empties without finding a solution, the puzzle is unsolvable — and the solver reports that immediately.

State Space Representation

For BFS to work efficiently, the solver needs a way to represent each board state compactly and to detect when it has already visited a state. ChromaOracle represents each tube as a stack of colors, and the full board as a collection of these stacks.

To avoid exploring the same state twice — which would waste time and memory — the solver generates a canonical key for each state. This key is a normalized string representation of the board that treats identical arrangements as the same state regardless of tube ordering. If two boards have the same tubes with the same contents, just in a different left-to-right order, they produce the same key and are recognized as duplicates.

This deduplication is critical. Without it, the solver would revisit the same positions millions of times, making it impractically slow. With it, the solver only processes each unique state once.

Why BFS Guarantees the Shortest Solution

The guarantee comes from the order of exploration. BFS processes states strictly by their distance from the start, measured in number of moves. Every state at distance N is processed before any state at distance N+1. Therefore, the first time the solver reaches the goal state, it has arrived via a path of length N, and no path of length less than N exists — because all shorter paths were already fully explored.

This is a mathematical property of the algorithm, not a heuristic or approximation. The solution BFS returns is provably optimal.

BFS Versus DFS

ChromaOracle also supports depth-first search (DFS) as an alternative algorithm. DFS works differently: instead of exploring layer by layer, it follows a single path as deep as possible before backtracking.

The tradeoffs are:

  • BFS finds the shortest solution but uses more memory, because it must store all states at the current depth level simultaneously.
  • DFS finds a solution faster in many cases and uses less memory, but the solution may not be the shortest. It returns the first valid path it stumbles upon, which might be much longer than necessary.

For most players, BFS is the right choice — you want the fewest moves. DFS is useful when you just want any solution quickly, or when the puzzle is so large that BFS runs out of memory.

How Mystery Mode Works

One of ChromaOracle's most distinctive features is Mystery Mode, designed for puzzles that contain hidden or unknown colors. In many puzzle games, some tube slots display a question mark instead of a color, and the actual color is only revealed when that layer becomes the top of its tube.

ChromaOracle handles this through permutation analysis:

  1. The solver identifies all positions marked as unknown.
  2. It generates every possible assignment of colors to those positions that is consistent with the puzzle's rules — each color must appear the correct number of times.
  3. It solves every resulting puzzle independently using BFS.
  4. It analyzes all solution sets to find moves that are safe regardless of what the hidden colors turn out to be.

This is called finding the "common prefix" — the longest sequence of moves that appears at the start of every solution across all possible color assignments. These moves are guaranteed to be correct no matter what the unknowns reveal.

This approach transforms a problem of uncertainty into a problem of exhaustive analysis. Instead of guessing, the solver considers every possibility and tells you exactly which moves are risk-free.

Performance and Practical Limits

The state space of a color sort puzzle grows exponentially with the number of tubes and colors. A simple puzzle with five colors might have a few thousand reachable states. A complex puzzle with twelve colors can have millions.

ChromaOracle solves puzzles on its server, in an engine written in Go. When you press Solve, your browser sends the board, and the server sends back the moves. Across the boards players solved between April and November 2026, half of the searches finished in under one second, and nine in ten finished in about two seconds.

BFS gets a time budget of a couple of seconds. If it has not finished by then, which happens mostly on boards with many colors, the solver switches to depth-first search. DFS finds a solution quickly but cannot promise the shortest, so the answer is marked as possibly not the shortest. Mystery Mode gets a longer budget, because it has to search every possible arrangement of the hidden colors.

The server also keeps every board it solves, without anything that identifies the player. When someone enters a board that was solved before, even with the tubes in a different order or the colors renamed, the server returns the stored answer instead of searching again. Before it sends a stored answer, it replays every move on the new board to check that the answer really solves it.

The Engine Architecture

For readers interested in the implementation, the engine is a small Go package organized by job:

  • Board stores each tube as four slots plus a fill count, generates the legal moves from a position, and builds a canonical key that is the same for every left-to-right order of the tubes, so the search never visits a position twice.
  • Search implements BFS and DFS over those boards, each with a time budget.
  • Mystery enumerates every arrangement of the hidden colors, solves each one, and finds the moves that every solution starts with.
  • Validation checks that the board is well formed, for example that the color counts add up, before any search starts.
  • Replay plays a list of moves on a board and confirms that each move is legal and that the board ends solved.

The board model in your browser, which handles editing, validation messages and playback, is a separate TypeScript module.

Frequently Asked Questions

Why does ChromaOracle sometimes take longer on certain puzzles?

Solving time depends on the size of the state space, which is determined by the number of colors, tubes, and empty slots. More colors and fewer empty tubes mean more possible states to explore. A twelve-color puzzle with one empty tube has a vastly larger state space than a four-color puzzle with three empty tubes.

Can the solver fail to find a solution?

If a solution exists under the solver's move rule, BFS will find it, given enough time. If BFS completes without finding one, no sequence of whole-run moves can solve the board, and ChromaOracle says so. The most common cause is a wrong color in the entry, so check the board before you give up on the level.

Is the BFS solution always the best possible?

When the search finishes within its time budget, yes: no sequence of the solver's moves is shorter than the one BFS returns. Two caveats apply. The count is in whole-run moves, so in a one-ball-per-tap game your tap count can be higher. And if BFS runs out of time on a very large board, the answer comes from DFS and is marked as possibly not the shortest.

How does Mystery Mode know which moves are safe?

Mystery Mode solves the puzzle for every possible assignment of hidden colors, then compares all the solutions. A move is marked as safe only if it appears in the optimal solution for every single possibility. This means the move is correct no matter what the hidden colors turn out to be.

Stuck on a puzzle?

Enter your colors into ChromaOracle and get a step-by-step solution in seconds.

Try ChromaOracle Solver

Related Guides