Let’s say I have an object, called “Tile”, which has both a name and a list of directions. We’ll assume that each tile has a 3x3 grid of pixels, which can either be on or off. The middle center pixel (designated with a “N” in the diagram) of the tile turns on when the North direction is “True”. The center left pixel (“W” in the diagram) of the tile turns on when the West direction is “True”. The center right pixel (“E”) of the tile turns on when the East direction is “True”. The bottom center pixel (“S”) of the tile turns on when the South direction is “True”. The middle pixel (“C”) is always on.
Diagram:
N
WCE
S
Each tile can only have one start and end, so there are 6 possible tiles. (Straights East-West and North-South, and all 4 turning pieces which form 90 degree angles)
Here’s an example tile, complete with attributes:
Tile1:
-North: True
-East: False
-South: False
-West: True
Here’s what that tile looks like, if dashes are “off” pixels and percent signs are on pixels:
-%-
%%-
——-
Let’s say I have a list of these tiles, where each tile connects to the one in the list before it, and I am procedurally generating them.
The idea is to be able to generate paths of arbitrary lengths, which do not need to exist inside the bounds of an array.
Of course, I want my map of tiles to be logically sensible, so it cannot have more than 3 lefts or rights in a row. My current “solution” is to have a counter where I subtract one if it turns to the right of the current tile, and add one if it turns to the left. I could then force it to choose a left-turning piece if the counter is at -3, and force it to choose a right turning piece if the counter is at 3. (This algorithm will work with my current generation methods, that is not the problem.)
What is the most efficient way, given the past tiles and their respective directions, to determine whether to increment or decrement the counter?
Sorry if this is a little verbose, I couldn’t think of a better way to phrase my question.
Edit: To clarify, the goal of the algorithm is to determine whether a tile given turns left, right, or straight (which isn’t really a turn, but IDC) based on the previous tiles and return 1, -1, or 0, respectively. That’s it.