Tile Link: The Path-Finding Problem I Did Not Expect
When I started building Tile Link, I thought the matching logic was the game. Select a tile, find its pair, clear them both. Simple. What I didn't account for was the path-finding constraint at the heart of the game: two tiles can only be matched if they can be connected by a line bending no more than twice. That single rule turned a casual matching game into a genuine algorithmic challenge.
Implementing the Two-Bend Rule
The naive approach was brute force: for every pair of selected matching tiles, try all possible L-shaped and Z-shaped paths between them and check if any is clear. This works, but it's slow on a full grid and the code became an unmaintainable mess of nested conditionals. I replaced it with a cleaner search. Given two tiles A and B, I enumerate all possible single-turn column or row values and check whether a path through that turn point is unobstructed. For two bends, I iterate over all open cells as potential first turn points, find the set of second turn points from there that reach B in one straight segment, and verify both segments are clear. The key insight is that with at most two bends, the number of candidate paths is bounded and small — you don't need a full pathfinder. A targeted geometric sweep is fast enough to run on every tile selection with no perceptible lag.
Generating Boards That Are Always Solvable
A random shuffle of matching tile pairs on a grid is not guaranteed to be solvable. In practice, about 30% of random arrangements produce a board where the first available match creates a configuration where remaining tiles can no longer be linked under the two-bend constraint. I considered post-hoc solvability verification with a regenerate-on-fail loop, but that approach occasionally loops for hundreds of iterations on large grids before finding a valid layout. Instead I switched to a construction approach: place tiles in matching pairs by first computing whether a valid path exists between two candidate positions before committing the placement. This is slower to generate but guarantees every board starts fully solvable. Generation takes under 50ms even for the largest grid size, so players never notice the overhead.
Visual Path Feedback Is the Game Feel
Once the algorithm worked, I realized the path itself needed to be visible. When you select a matching pair, the connecting path should animate onto the screen before both tiles disappear. This sounds cosmetic but it's actually critical to learning. Without the visible path, players don't understand why some matches work and others don't — the two-bend rule feels arbitrary and invisible. With the path, you see exactly why a connection is valid. I draw the path as a polyline that traces segment by segment over 120ms, with the tiles holding their selected state until the animation completes. The disappear animation fires immediately after. Players watching the path form develop an intuitive spatial model of the constraint much faster than players who don't see it — their subsequent selections become more deliberate and their scores climb noticeably faster.
Browse All Games