programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Program to solve simple mazes

Alex Monari
Greenhorn
Posts: 11
Hi All,

I'm attempting to understand recursion using the following matrix challenge - https://drive.google.com/file/d/0B1nMyjpx71zXMGVDVmhGODBTUEk/view?usp=sharing

Here https://drive.google.com/file/d/0B1nMyjpx71zXbUxuYmdxeW54RDA/view?usp=sharing is an example of the sample mazes provided.

Below are my steps regarding a solution:

S1 - Provide test case options to user through switch statement.

S2 - File Read and extract string - For this step I intend on using a method which will return a string having read the file and performed the necessary checks.

S3 - MazeWorker class - this class will figure out maze and present outcome.

S1 CODE BELOW:

S2 CODE BELOW

I'm stuck on how to execute step 3 above.

I kindly need some suggestions regarding how to build the maze logic rather than me copying some online solution.

Any ideas?

William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
I kindly need some suggestions regarding how to build the maze logic rather than me copying some online solution.

I like the "flood fill" approach for simplicity and cool visualization possibilities.

Imagine starting a flood of paint at your maze starting point.

In a stepwise fashion, go through all the currently flooded locations - if adjacent to an unflooded spot, flood it & recording the iteration number.

When the flood reaches the goal backtrack through the lowest numbered spots to get the path.

Bill

Carey Brown
Saloon Keeper
Posts: 3323
46
'matrix' is an int[][], what does an int value represent? A typical maze implementation will use an int where the lowest 4 bits can be turned on or off depending on whether there is a wall or not in a particular direction (north, south, east, or west). I'm not sure what approach you're using.