Original interactive / Swap, clear, fall

One swap.
Every cascade accounted for.

This 6×6 board starts with no matches and uses five tile types. Clear every horizontal or vertical run of three or more, compact each column downwards, then fill the gaps from the seeded stream. New matches trigger the next layer.

Keyboard: arrow keys move focus between cells; Enter or Space selects a tile. A second selection makes the swap.

Choose one tile, then an orthogonal neighbour. Only a swap that makes three in a row or column is kept.

A legal swap is a test about the resulting board.

The board has six rows, six columns and five geometric tile types. Two tiles may be exchanged only when they share an edge, not merely when they are near one another. After the exchange, the model searches every horizontal and vertical run. If no run contains at least three equal tiles, the swap is rejected and the original board remains.

This is a rule about a position, not about the player’s intention. Moving two unlike tiles can be useful when each becomes part of a run. A run formed entirely elsewhere would also be found by a whole-board scan, although the fixed starting board deliberately contains none. That starting condition ensures the first match can be traced to the swap.

Choose two neighbours on the board and inspect the result. For a known first move, swap the tiles at row 1, columns 2 and 3. The resulting vertical run resolves, surviving tiles fall and replacements arrive from a fixed random stream. Resetting restores both the original board and that stream’s position, so the same move can be examined again exactly.

Find runs first, then count unique cells.

A horizontal scan records consecutive equal values in each row. A vertical scan does the same in each column. Runs of length three or more contribute their cell indices to a set. Because a set contains each index once, a tile at the intersection of a horizontal and vertical match is cleared once rather than counted twice.

This distinction matters for scoring and for gravity. Suppose five cells form a cross. Counting the horizontal trio and vertical trio separately would report six removals, but only five actual cells leave the board. The demo’s layer report counts unique cells and therefore agrees with what gravity must move.

Longer runs are not shortened into groups of exactly three. Four connected equal tiles clear all four; five clear all five. There are no special tiles, score multipliers or unexplained exceptions. Those could be added as separate rules, but excluding them keeps the relationship between a match and a cascade easy to audit.

Gravity works one column at a time.

Once the matched set is known, each column is read from bottom to top. Every surviving tile is written into the lowest available position while preserving the survivors’ order. Only after that compaction are the remaining spaces at the top filled. The random generator supplies values from one to five, with the same range used during board creation.

The operation does not swap arbitrary tiles or move them sideways. A survivor cannot fall past another survivor, and a replacement never appears below a tile that survived the clear. These invariants are tested on small boards where the expected final order can be written by hand.

After every refill, the model scans the whole board again. Each iteration is one cascade layer. “Previous layer” and “Next layer” display the stored board after the swap and after each resolution, rather than running an animation whose intermediate states disappear. This is also why reduced-motion settings lose no information: the entire process is available as discrete steps.

Why a chain can feel lucky.

The first clear is often visible before a swap. Later clears depend on replacements that have not yet appeared and on survivors whose new positions may be several rows away. The player chooses the first cause, but the deterministic rules then propagate it through states that are harder to hold in working memory.

A fixed seed makes that chain reproducible; it does not make it obvious. Changing which earlier candidate swaps were attempted would normally change the random stream, so a later cascade could differ even on the same visible board. The demo therefore keeps the refill state as part of the play session and resets it explicitly.

For a controlled experiment, the statistics button takes a different approach. Every one of its 1,000 trials starts from the original board. A seeded choice selects one of the 60 horizontal or vertical adjacent pairs. Illegal candidates are counted as “No match”, while legal candidates resolve until stable. This samples candidate actions, not a sequence of ordinary play.

Read the distribution, including rejected moves.

For the published board and statistics seed, 814 candidates make no match and 186 are legal. The legal outcomes contain 139 one-layer results, 32 two-layer results, 11 three-layer results and four results with at least four layers. A legal swap averages 1.382 layers and 4.430 cleared tiles in this particular experiment.

Those figures are not a universal cascade rate. They are an output of this exact starting arrangement and model. The candidate sampler does not first filter to legal swaps, which is useful when the design question is how often a random attempt succeeds. If the question instead concerns a player who already sees legal moves, the denominator should be the 186 legal trials.

Run the button before and after playing. The answer is unchanged because statistics always restart from the original board and use their own seed. This separation prevents your moves from contaminating the comparison. It also demonstrates a useful experimental rule: decide what population is being sampled before interpreting a percentage.

Refill rules are difficulty rules.

Five tile types, immediate whole-board rescans and independent top replacements create one particular rhythm. Fewer tile types would usually make accidental runs easier, while restricted replacement positions could create different chains. Neither statement is a measured property of this demo until the rule is implemented and tested. The model’s value is that such a change can be isolated.

Other matching mechanics change the basic action itself. Compare the deterministic pair-building in merge games, or the position search in sorting and unblock puzzles. The number-gate experiment also contrasts a chosen action with everything it causes next. Return to the mechanics collection for the full set.

Sources and method.

No external statistical claim is made. The board, moves, collapse order, cascade records and all reported counts come from this page’s original pure functions. Independent tests cover run detection, intersecting matches, rejected swaps, falling order, deterministic refills and the 1,000-trial totals.

The two catalog names and destination paths were checked against the public catalog API on 5 December 2026, following every nextCursor. See our editorial standards for how original demonstrations and external examples are separated.

Questions to try next.

Does a swap stay on the board if it makes no match?

No. This demo rejects that move and restores the original order. It also leaves the refill random stream unchanged, so trying an illegal swap cannot alter the next legal outcome. Other matching games can use different rules; that choice belongs to the model rather than to the genre’s name.

What creates a cascade?

A swap creates at least one run of three or more. Those cells are removed together, surviving tiles fall within their columns, and seeded replacements fill the empty spaces at the top. If that new board contains another run, resolving it produces the next cascade layer.

Are the statistics a prediction for every match-three game?

No. They describe only this original board, five tile types, legal-swap rule and downward refill. Every trial starts again from the same arrangement, and a uniformly chosen adjacent pair is not the same as a uniformly chosen legal move. Different boards and refill rules need their own measurements.

Why can a four-in-a-row clear four tiles here?

The demo clears every cell belonging to a horizontal or vertical run of at least three. It does not turn a longer run into a special piece. A crossing horizontal and vertical run is counted as one set of unique cells, so their shared intersection is removed only once.