• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maze game

 
Becky Bloomwood
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i'd like some information on creating a very simple maze program. No graphical features of java need be used. The walls would be represented by asterixes and the robot would be made of the keyboards full stop character. The robot will try to find its way out of the maze. I would think that the maze would be made from a 2 dimensional array and the code would be looped until the robot found its way out, but other the that i'm not sure. Can anyone help?

Thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"de pressed",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
search the Programming Diversions forum for 'maze' and you'll find some
interesting threads
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Becky Bloomwood"

Your name appears to be based on a fictitious character. Please choose a more appropriate name.
 
Ryan McGuire
Ranch Hand
Posts: 1073
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I see it, there are two pieces to this: A) Making a maze and B) Solving the maze.

A) Making a maze.
I agree that the most obvious data structure, a two-dimensional array, is probably correct. But an array of what? Strings? chars? ints? A custom class? Some standard library class? Well what information do you need for each cell? You might say that you need to know whether each of the four surrounding walls is solid or not, but then the state of any one wall has to be maintained in the the two squares that the wall separates.

The other option is to track the state of only two walls (perhaps the top and left walls) for each square. The plus side of this approach is that you have to manipulate only half as many values per cell. The minus side is that the entire right column and bottom row of the maze pose strange border condition problems.

There is a neat algorithm for generating a maze:


B) Solving the maze
The simplest algorithm for solving a maze is to have the "robot" stay against one wall. Whenever the robot enters a new cell, it should try to turn left, go straight, turn right, or do a u-turn, in that order.

Cool?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started to write up some of my experience playing with mazes and then thought to look at Wikipedia. It's always worth a visit.

http://en.wikipedia.org/wiki/Maze
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic