Algorithm solves three-color Free-Flood-It on fixed-height grids efficiently

Three-Color Free-Flood-It on Fixed-Height Grids Is Polynomial-Time Solvable

Computational ComplexityData Structures and Algorithms

Summary

Free-Flood-It is a puzzle game where you change the colors of connected squares to make the whole board one color with as few moves as possible. The paper presents an algorithm that finds the best way to solve this game on rectangular grids with three colors and a fixed height. The authors show that their method runs in time that grows reasonably with the board size, making the problem easier to solve than previously known. They also provide approximation methods for more general cases.

What this means in practice

  • For game developers: Implement efficient solvers or hints for three-color Flood-It puzzles on fixed-height grids to enhance gameplay experience.
  • For algorithm designers: Use the polynomial-time approach for optimizing similar coloring or partitioning problems in graphs with layered structures.

A theory result. No direct application yet.

Authors

Yuxuan Zhou

Abstract

We give a deterministic algorithm for \textsc{Free-Flood-It} on rectangular grids $P_k\square P_n$ with at most three colors. For every fixed height $k$, it computes the minimum number of moves and an optimal sequence in $N^{O(k^2)}$ time, where $N=kn$. This resolves the previously open three-color case on complete $3\times n$ boards. The proof uses a representation of flooding strategies as paintings by connected regions. We show that an optimal painting can be chosen so that its regions form a rooted tree with strong restrictions on the colors along ancestral paths. These restrictions make the part of the tree visible in any fixed-size connected window admit only polynomially many descriptions. The remaining common ancestors may form an arbitrarily long chain. We retain that chain on a stack and use a finite context-free recurrence to minimize the total painting cost without enumerating all possible stack contents. Connectivity information at the boundary ensures that the resulting local descriptions assemble into one valid global painting. The argument also applies to graphs supplied with an ordering into connected layers of bounded size, provided every edge lies within one layer or joins consecutive layers. A family of three-row boards shows that the unbounded ancestor chains handled by the algorithm are necessary even for optimal paintings. For any fixed height and palette size, we also give a deterministic EPTAS and a randomized sampling variant with an explicit failure-probability bound. These approximation results use a separate algorithm with single-exponential dependence on the move budget.