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:
 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)
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement