Pages

Tuesday, January 6, 2026

Game of Constraints

I've been playing a lot of this fun game lately. It's called "Flow Free" on the Apple store. At a superficial level, this puzzle game looks almost trivial. You are given a grid and several pairs of colored dots. The task is to connect each pair with a continuous path of the same color. Paths cannot cross, cannot branch, and in the completed puzzle every square of the grid must be occupied by exactly one path segment.




Despite the simplicity of the rules, the puzzles quickly become nontrivial. The reason is that the game is not really about drawing paths. It is about satisfying a tightly coupled system of constraints on a discrete structure. I tend to not think too much consciously while playing and just solve the puzzles, but it occurred to me today that it might be an interesting math problem to think about too.

Mathematically, the grid can be viewed as a finite planar graph. Each cell is a vertex, and edges connect orthogonally adjacent cells. Each color defines a pair of terminal vertices that must be connected by a simple path. The paths for different colors must be vertex-disjoint, and their union must cover the entire graph.

This formulation already places the game in familiar territory. It is a multi-terminal path-routing problem with global coverage constraints. In general, problems of this type are computationally hard. Even deciding whether such a set of disjoint paths exists on a grid graph is closely related to NP-complete problems such as Hamiltonian path variants and exact cover.

What makes the puzzle solvable by humans is not that it is easy in principle, but that the constraints are extremely local and rigid. Every non-terminal vertex must have degree exactly two in the final solution. Every terminal must have degree exactly one. No vertex can have degree zero, three, or four. These local degree constraints dramatically reduce the space of admissible configurations.

Once you internalize this, the puzzle stops feeling like a search problem. You are not exploring a large space of possibilities. Instead, you are eliminating impossibilities. Certain moves are immediately forbidden because they would create a dead end, isolate a region, or force a vertex into an invalid degree later. The grid becomes a fragile object: small violations propagate quickly and cause global failure.

Planarity plays an important role here. Because the graph is planar and paths cannot cross, any closed loop you form acts as a topological boundary. If a loop encloses a region of the grid, that region must be internally solvable using only the terminals it contains. If it is not, the loop is invalid. This introduces a kind of topological bookkeeping that happens implicitly as you play.

Another way to see the game is as a constrained path cover problem. You are decomposing the graph into a collection of disjoint simple paths with prescribed endpoints. Full coverage forces the solution to be extremely structured. In many puzzles, once a few forced segments are identified, the remainder of the solution becomes essentially unique. This is why optimal solutions often feel inevitable rather than clever.

From this perspective, the “difficulty” of a level is not about the number of moves required, but about how late the constraints fully determine the configuration. Easy puzzles reveal their forced structure early. Hard puzzles delay it, allowing many locally valid but globally incompatible partial solutions.

What I find interesting about this game is how directly it exposes a general pattern in constraint-based problems. You rarely solve such problems by constructing a solution outright. Instead, you narrow the space of admissible solutions until only one remains. The work is done by constraints, not by choice.

Seen this way, the puzzle is less about connecting dots and more about discovering a rigid combinatorial object hidden inside a simple set of rules, whether played consciously or not.

No comments:

Post a Comment

Can you simulate the laws of physics on a computer?

I watched a talk by Prof. David Tong at TIFR today. The talk itself was about renormalization groups, which I’ll make a separate post about,...