473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Solving Java Mazes

23
Hello. I'd like to start off by saying that this is not a homework problem of any sort. I am a high school student who frequents cs competitions, and I have never been able to solve problems concerning mazes. For instance, consider the following typical example:

s1000
01000
01000
01111
00101
e1111

The s and e represent starting positions, while the 0's represent "walls" or areas that cannot be traversed. The 1's signify traversable spaces. The object is to find the shortest length from start to end, in this case 9 moves.

I have googled around for solutions to this kind of problem, and have found ones that are either too robust (I want only a few methods inside a single class) or too complex (I must be able to memorize the code to some degree).

I am sure that a concise solution exists, and I would appreciate any help.

Thanks in advance,
anon
Sep 5 '08 #1
1 1341
Nepomuk
3,112 Expert 2GB
Hi anon538!
I think what you should be trying to do is to implement a Breadth-first search. (Example implementations in Python, C and C++ can be found on wikipedia.) In the maze you gave, any search would go the same with most searches until this point:
Expand|Select|Wrap|Line Numbers
  1. sv000
  2. 0v000
  3. 0v000
  4. 0vv11
  5. 00101
  6. e1111
(v being a visited point)
Then a Breadth-first search would explore the two neighbouring 1s, then those next to them and so on. The first solution that you find that way will be an ideal (= shortest) solution.

Greetings,
Nepomuk
Sep 5 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Vinay Aggarwal | last post by:
I have been thinking about the lazy initialization and double checked locking problem. This problem is explain in detail here http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html...
2
by: nib | last post by:
What kind of problems is Java best at solving?
19
by: nb | last post by:
What kind of problems is c# best at solving?
16
by: Martin Jørgensen | last post by:
Hi, I've made a program from numerical recipes. Looks like I'm not allowed to distribute the source code from numerical recipes but it shouldn't even be necessary to do that. My problem is...
1
by: bparanj | last post by:
Hello, I have been a software developer for the past 10 years now. I get job descriptions that requires problem-solving skills as one of the most desirable skills in a candidate. But there are...
1
by: bparanj | last post by:
Hello, I have been a software developer for the past 10 years now. I get job descriptions that requires problem-solving skills as one of the most desirable skills in a candidate. But there are...
1
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is...
3
by: deanchhsw | last post by:
Hello, I'm trying to build a program that solves sudokus and prints out the result on the screen. Here's the code for the class SudokuBoard. this will later be called in a class Sudoku. I'm a newbie,...
2
by: thijo | last post by:
hi, i'm coding to take a input vector inputdata, and continuously find standard deviation to count how many distinct data ar available.for this i implement a small method called findk(). public ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.