Back
Queen icon
ArticleAlgorithms8 min read2026-09-06

Constraint Propagation and Arc Consistency in N-Queens

Constraint Propagation and Arc Consistency in N-Queens — Queens.game

Every time you place a queen in the Queens game, you're doing something computer scientists have a name for: constraint propagation. That instant feeling of "well, this whole region is dead now" isn't intuition — it's logic you can formalize, and it's the same logic that powers Sudoku solvers, scheduling software, and the classic N-Queens problem in computer science.

This article is for anyone who enjoys Queens or similar puzzles and wants to understand the machinery underneath the fun. You don't need a programming background. We'll use the puzzle you already know to explain ideas like constraint satisfaction problems, arc consistency, and why brute-force guessing falls apart as boards grow larger.

By the end, you'll see why a well-placed queen can eliminate dozens of future possibilities before you even notice, why some puzzles feel "obvious" while others demand real search, and why this single idea — narrowing possibilities before guessing — shows up everywhere from Sudoku grids to serious optimization problems. Let's start with the basic vocabulary: what exactly is a constraint satisfaction problem?

What Is a Constraint Satisfaction Problem?

A constraint satisfaction problem, or CSP, is a puzzle broken into three parts: variables, domains, and constraints.

  • Variables are the things you need to decide — in N-Queens, one variable per row, representing where that row's queen goes.
  • Domains are the possible values each variable can take — for an 8x8 board, each row's queen could sit in columns 1 through 8.
  • Constraints are the rules that limit which combinations are valid — no shared column, no shared diagonal.

Sudoku fits the same mold: each empty cell is a variable, its domain is the digits 1–9, and the constraints demand uniqueness across rows, columns, and boxes. The Queens puzzle you play in your browser adds one more constraint layer, one queen per colored region, but structurally it's the same CSP.

Once you see puzzles this way, solving them becomes about narrowing domains systematically rather than guessing.

Why Brute Force Search Explodes

The naive approach to N-Queens (or a Queens puzzle grid) tries every way to place queens one per row, then checks each placement for column and diagonal conflicts afterward. Since each queen must land in a distinct row, there are n! ways to assign columns to rows before any conflict-checking even begins.

That factorial growth is brutal:

  • n = 8 → 40,320 assignments
  • n = 12 → about 479 million
  • n = 16 → over 20 trillion

Most of these assignments are wasted work — a queen placed in row 1 might already conflict with row 2's queen, yet naive search keeps filling in rows 3 through n before noticing. It never uses what it already knows to skip bad branches early.

This is exactly the gap constraint propagation closes: instead of generating full assignments and testing them, it prunes impossible values as soon as a conflict becomes certain.

Constraint Propagation: Pruning Before You Guess

Constraint propagation means removing values from a variable's domain as soon as you know they can't be part of any solution — rather than waiting to discover the conflict later through trial and error.

In Queens, every placed queen immediately shrinks the options for everyone else. Place a queen in a region, and you can instantly eliminate:

  • Every other cell in that row and column
  • The diagonally adjacent cells (touching corners)
  • Any cell in another region whose entire remaining domain has now collapsed to zero

That last point matters most. If a color region only has three legal cells left, and a queen placement removes all three, propagation catches that dead end immediately — no need to keep searching down that branch.

Google's OR-Tools CP-SAT solver uses exactly this mechanism: each assignment triggers propagation that restricts remaining variables before the next choice is made. The practical effect for a human solver is the same one experienced Queens players rely on instinctively — cross off the impossible cells first, and the real decision points become obvious.

Arc Consistency and the AC-3 Idea

Arc consistency looks at constraints one pair at a time. Take two regions in a Queens board, call them A and B. The pair is arc consistent if every remaining cell still available to A has at least one compatible cell in B — one that doesn't share a row, column, or diagonal touchpoint. If a cell in A has no such partner in B, that cell can never be part of a valid solution, so it gets removed.

An AC-3-style pass, named for Alan Mackworth's 1977 algorithm, automates this checking. The method keeps a queue of region pairs to examine:

  • Pick a pair, check each candidate cell for a supporting match in the other region.
  • Remove any cell that has no support.
  • If a region loses a cell, re-add all pairs involving that region to the queue, since removing an option there might strip support elsewhere.
  • Repeat until the queue is empty.

What makes this useful for Queens is the ripple effect. Shrinking one region's options can cascade through the board, tightening neighbors that seemed unrelated. The process doesn't guarantee a full solution, but it often narrows the search dramatically before any guessing starts.

N-Queens Step by Step: Watching Domains Shrink

Picture a 6x6 board. Before any queen is placed, each row's domain — the set of columns a queen could legally occupy — contains all six columns.

Place a queen in row 1, column 3. Propagation immediately updates every other row's domain:

  • Column 3 is removed from rows 2 through 6 (no shared columns).
  • In row 2, column 2 and column 4 are removed (one step diagonally away).
  • In row 3, column 1 and column 5 are removed (two steps diagonally away).
  • In row 4, column 6 would be removed if it sat three steps down the diagonal, and so on for any row still in diagonal range.

Row 2's domain shrinks from {1,2,3,4,5,6} to {1,5,6}. Row 3 loses column 3 for the column constraint and columns 1 and 5 for the diagonals, leaving {2,4,6}.

Now suppose row 2 gets assigned column 1. That triggers a second round: column 1 disappears from every remaining row, and the diagonal neighbors of (2,1) — column 2 in row 3 — get pruned too. Row 3's domain, already down to {2,4,6}, drops to {4,6}.

Each assignment cascades outward, shrinking domains before the solver ever tries a value that's doomed to fail. In a colored-region Queens puzzle, the same shrinking happens per region: once a queen claims a cell, every other cell in its row, column, diagonal neighbors, and often its own region becomes unavailable, narrowing the next region's choices automatically.

Sudoku's Familiar Version of the Same Trick

If you've solved a Sudoku puzzle, you've already done constraint propagation by hand. When a cell has only one possible number left because the other eight are taken by its row, column, and box, that's a "naked single." You fill it in, and that new number removes possibilities from every cell it touches. That chain reaction is exactly the domain-shrinking process described earlier, just wearing a different name.

Sudoku's "hidden single" is the same idea from another angle: a number that can only go in one cell within a row, column, or box, even though that cell still looks open to other digits. Spotting it means reading the constraints on the value, not just the cell.

Both tricks work because Sudoku's rules are really just constraints linking variables together, the same structure that makes Queens puzzles solvable through logic rather than guesswork. You were pruning search spaces long before anyone gave it a formal algorithm name.

Why Propagation Doesn't Solve Everything

Arc consistency is a filter, not an oracle. It removes values that can't possibly work, but it doesn't guarantee every remaining value leads to a solution. Once propagation stalls — no domain shrinks further, yet more than one candidate remains in some region or row — the solver still has to guess a value and try it, backtracking if that guess fails.

This isn't a flaw in AC-3 specifically; it's a structural limit. N-Queens Completion, the version of the puzzle where some queens start pre-placed, has been shown to be NP-complete. That means no known technique — propagation included — can guarantee a fast solution for every instance as the board grows. Some configurations genuinely require search.

So think of propagation as narrowing the haystack, not finding the needle. On a well-designed Queens puzzle, that narrowing is usually enough to make the remaining guesses trivial. On harder or adversarial boards, it's just the first stage of the work.

Keep exploring on Queens.game