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 is 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:
Code:
Each path can only have one start and end, so there are 6 possible tiles. (Straights East-West it North-South, and all 4 turning pieces which form 90 degrees.)
Let’s say I have a list of these tiles, where each tile connects to the one behind it, and I am procedurally generating them.
Of course, I want my map 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?
To clarify, I want an ALGORITHM, not an implementation. (Though, if it helps you explain or demonstrate the algorithm, you can implement it in whatever language you need to)
Diagram:
Code:
N
WCE
S
Each path can only have one start and end, so there are 6 possible tiles. (Straights East-West it North-South, and all 4 turning pieces which form 90 degrees.)
Let’s say I have a list of these tiles, where each tile connects to the one behind it, and I am procedurally generating them.
Of course, I want my map 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?
To clarify, I want an ALGORITHM, not an implementation. (Though, if it helps you explain or demonstrate the algorithm, you can implement it in whatever language you need to)