Mapping "valid" tile sequences to number series

22 Views Asked by At

I'm interested in understanding the maths behind a satisfying time-waster game called Noodles!. In one of the game varieties there's a grid of tessellating hexagons with pipes drawn on them, and you must make all the pipes line up to win:

screenshot of tessellating hexagons on Noodles! game

Each of the tiles (and its orientation) can be described by a binary number, representing whether there is a pipe on the top edge (1), top right edge (2), bottom right edge (4), etc. So the 1-pipe tile's orientations would be 1, 2, 4, 8, 16, or 32; the 2-pipe tile with adjacent pipes would be 3, 6, 12, 24, 48, or 33 as it rotated.

The game doesn't have any 0-, 5-, or 6-pipe tiles, so all possible valid and invalid tiles for a slot are described by the numbers 0-63 excluding 0 (0-pipe), 31, 47, 55, 59, 61, 62 (5-pipe) and 63 (6-pipe).

Though it's likely obvious, a tile is in a valid slot if its pipes match up exactly with a neighbouring tile's pipes on that edge, which also means no pipes can be on edges on the outside of the board.

I can count up the number of 'probably valid' tiles & orientations by counting the number of different possible pieces & orientations for each type of slot (those with 0, 1, 2, 3, 4 adjacent external edges) but this doesn't take account of any internal validity. (There are 96,717,323,005,846 externally valid boards on a 5x5 grid, fyi!)

I'd like to achieve one thing in particular, but any interesting mathematical observations or approaches, places for me to research would be awesome too:

Is it possible for me to create a discrete (limited) number space, where each number represents a valid board, while representing no invalid boards, and ideally representing all valid boards? I can compute all valid combinations then index them, but this feels inelegant, and like there's a general solution, any tips?

I'm sure there's some aspect of using paths over the tiles (Hilbert curves?) to turn my 2D board into a 1D sequence of numbers (that I can add, then map) is a reasonable approach, but honestly I'm a bit lost! Is anyone interested in helping?

(Context: I once earned an MSci in Physics, so I still have some advanced training in maths floating about in here, but limited set & number theory!)