This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Maze game

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
search the Programming Diversions forum for 'maze' and you'll find some
interesting threads
 
author
Posts: 4281
34
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Becky Bloomwood"

Your name appears to be based on a fictitious character. Please choose a more appropriate name.
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic