Write a program in Java that randomly generates two-dimensional mazes and prints
them to the console. For example, a possible output might look like:
XXXXXXXXXXX
X X X
XXX X X X X
X X X X
X XXX X XXX
X X X
XXXXXXXXX X
The width of this maze is 11, and its height is 7. Your program should generate and
display 20 such mazes whose widths and heights are random odd numbers between 5 and
79, inclusive.
Each maze must be 2 entrances that are reachable from each other.
The following mazes do not meet the constraint:
XXXXXXX
X
XXXXX X
X X X There is only 1 entrance.
X XXX X
X X
XXXXXXX
X XXXXX
X X
X XXX X
X X X There are 3 entrances.
X XXX X
X X
XXX XXX
XXXXX X
X X X
X XX X X
X X X No path exists between both entrances.
X XXX X
X X X
XXX XXX
Feel free to use standard APIs in your solution.
Can any one help me in getting a logic to build a single maze atleast..! Constructing such a maze is been bugging me since two days !!!
PS: Attached is the proper image. Please download it to have better view of the mazes !
You can use code tags or HTML <pre> tags to make formatted text look right.
Ross Miller
Greenhorn
Joined: Jan 10, 2010
Posts: 7
posted
0
@Seetha : Yeah my first post in the Ranch ! :p
well, hmm.. my progress till now is to create a random odd number X odd number matrix using a two dimensional array filled with "X"s.
And i could get a random entry point and an exit point.
and i am stuck up at a point where i should actually create a path from entry to exit and which i mean the whole array should actually look like a maze !
any ideas to progress with this ? or rather generating a maze creating a path from entry to exit ??!!