• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need An Idea to solve This

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
puzzle.JPG
[Thumbnail for puzzle.JPG]
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what have you done so far? What problems have you encountered? And your thread title is not at all helpful.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and Welcome to JavaRanch
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use code tags or HTML <pre> tags to make formatted text look right.
 
Ross Miller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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 ??!!
 
Ross Miller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>
 
Ross Miller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XXXX XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXX XXXXXXXXX


A sample output of my above code :-|.


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't part of the assignment to figure out how to generate a maze?
 
Ross Miller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ofcourse objective is to generate a maze !
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, what do you have so far for the maze generation part?
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Froggy, please read your private messages.
 
Ross Miller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@David: Nothing as of now, except to create a 2D array filled with all X's and get a random entry and exit point for it.

and i am wondering how would i progress from here to generate a maze !
 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

  1. Initialize 2D array of ints to 0x0F where each of the 4 bits represents its four walls (north,south,east, and west).

  2. Initialize an empty array of 'neighbors' holding the X,Y position of potential neighbors.

  3. Select a random cell and add its four neighbors to the neighbor list.

  4. while neighbor list is not empty:


    1. Select a random neighbor.

    2. Knock down a random wall between neighbor and established cell.

    3. Add to neighbor list any available neighbors to the selected cell.


  5. Remove any two exterior walls.

  6. Draw.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic