I'm creating a game world that consists of a 16 x 16 x 16 rubix cube (pictured), where the individual cubes are floating in space. The cubes continuously move along a single set path that links up with itself at the end. It might be helpful to think of them as traversing a 3D maze. Are there any algorithms or solutions that could help me generate this path?
-
You just need a single closed loop path that visits each node?Dan Pichelman– Dan Pichelman2015-10-27 21:16:32 +00:00Commented Oct 27, 2015 at 21:16
-
Yes, that's exactly right.Adam– Adam2015-10-27 21:17:55 +00:00Commented Oct 27, 2015 at 21:17
-
1Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Askgnat– gnat2015-10-27 21:18:20 +00:00Commented Oct 27, 2015 at 21:18
-
I wonder if arrays can be nested, as well as the loops to populate them...user22815– user228152015-10-27 21:22:41 +00:00Commented Oct 27, 2015 at 21:22
-
Gnat, I'm afraid I'm very new to pathing algorithms so I've been completely stumped by the complexity of this task. I considered simply weaving the path up and down along the sides and working inwards but then the path end wouldn't be able to link to the path startAdam– Adam2015-10-27 21:24:42 +00:00Commented Oct 27, 2015 at 21:24
1 Answer
As I mentioned in a comment, one possible way to solve this is to weave a path back & forth across a face using 2 pencils. One pencil draws the beginning of the path, and the other draws the end.
Here's an example for one face:
+----------------+
|abcdefghijklmnop|
|ZYXWVUTSRQPONMLq|
|****ABCDEFGHIJKr|
|*###3210zyxwvuts|
|*###############|
|***************#|
|***************#|
|*###############|
|*###############|
|***************#|
|***************#|
|*###############|
|*###############|
|***************#|
|***************#|
|*###############|
+----------------+
One pencil starts in the top row, left column, "abcd..."
The other pencil starts in the 2nd row, left column, "ZYXWV..."
As you can see, both paths end in the left column, bottom 2 rows. At that point you move to the next face & repeat the process.
When you've finished you have to "parallel" paths. Just tie the ends together & you have your loop that visits each node.
a limitation
This only works because the number of rows (or columns) is a multiple of 2. If your grid was 15x15x15, you'd have a problem.
-
Thanks Dan, the pencil analogy really helped me figure this out!Adam– Adam2015-10-27 23:48:52 +00:00Commented Oct 27, 2015 at 23:48
