Ken-Soft

Software and the World

4D Maze - (Java)

Posted under General Development, Java, Mathematics, Software Development by Kenny on Wednesday 14 January 2009 at 12:23 am
Bookmark and Share

This is a simple implementation of a 4D maze written in Java. As of now it is entirely text based however, a simple GUI is currently under development. Either way, this simple implementation should be useful to modify and/or build off of.
The algorithm used to generate the map is quite simple and always generates a perfect maze.

1. Randomly choose a starting room
2. Add all surrounding rooms that have not been visited, or to a list
3. While their are rooms in the list randomly select one
4. Set the room to visited, and start again from step 2 using the current room

Note: the Java version used in this implementation uses recursion to do this.
This code has not been thoroughly checked for possible bugs, and I am sure there is a more efficient method to write a 4D maze. But, at the very least, it is flexible and each room of the maze is of class type Room4D and should be easy to modify.
The Jar file can be downloaded here: Maze4D.jar
To run from the command line:

java -jar Maze4D.java dimXYZU

Ex:

java -jar Maze4D.java 5

This initializes a 5×5x5×5 maze. Start = (0,0,0,0), Finish = (5,5,5,5)
that’s 5^4 rooms, 625 rooms, that’s a lot of rooms to navigate in 4D. :)

java -jar Maze4D.java dimX dimY dimZ dimU

Ex:

java -jar Maze4D.java 5 5 3 2

This initializes a 5×5x3×2 maze. Start = (0,0,0,0), Finish = (5,5,3,2)
5×5x3×2 = 150 rooms.

java -jar Maze4D.java

creates a default maze of dimensions 4×4x4×4

Note: be careful not to load a 4D maze that’s too big or Java will run out of memory, depending on your Java settings. For example creating a room that is 10×10x10×10, 10000 rooms, will likely cause an error caused by using too much memory. besides, a 10000 room is very, very complicated, especially in 4D.
4D maze java

Rect4D.java

Point4D.java

Room4D.java

Maze4D.java


4 Comments »

  1. Comment by Matt Hanson — January 14, 2009 @ 12:40 am

    Good writing. Keep up the good work. I just added your RSS feed my Google News Reader..

    Matt Hanson

  2. Comment by Kenny — January 14, 2009 @ 12:45 am

    Thanks alot! I’ll try to keep making stuff. :)
    You also have some very useful blog articles.

  3. Comment by Onendehopolve — February 24, 2009 @ 4:26 am

    Thank you!

  4. Comment by Joe Whitehead — August 24, 2009 @ 8:04 am

    Showed my brother this. The 4D Rubiks Cube site is awsome as well.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Copyright © 2009 www.Ken-Soft.com