Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How to backtrace in a maze...?

I think you are in the right direction. What I think you should do is keep checking for all direction unless you found the cavern. Right now you are checking for only one direction in each iteration because of the else clause. So when the call to explore returns you can't keep checking a different direction and essentially you don't backtrack. If you make your explore function return a Boolean field indicating whether you reached the cavern changing your code like this may work:

// move right
if ... // your condition to check if moving right
is possible and you didn't visit
// code to move right
found = explore()
//move down if didn't find cavern
if (!found) // and moving down is possible and
didn't visit
// code to move down
found = explore()
// keep checking other directions

Categories : Java

Related to : How to backtrace in a maze...?
Recently Add
How to convert this for loop into an enhanced loop
Do-while, try-catch loop error
JavaFx use String with Double on table column
Equal Spacing In print statements
Android Poor Image Quality When Saving Image From takePicture callback
Why ConcurrentHashMap put() return null but the item is put successfully?
Executing the java program from command prompt
Query multiple Entity attributes with List of values
Android Collections.sort - doesn't work properly
Gdx.files.internal(...) wrapper not working correctly
How to do character math?
Android - How to stack the views added dynamically?
Java: implement a loop with duplicate values in Array
Graphics paint component and loop trouble
Java: Transfer a file from server to client and from client to server
Problems with struts2 interceptor
Beginners Java Blue J returning a String in a method
How to pass Array of complex objects as a IN parameter in a stored procedure using JPA 2
Android: Finding fundamental frequency of audio input
Generic Java Logger output null.null for class and member name
How to use semaphores correctly
Hystrix: HystrixBadRequestException for failed validations
Sending a file over java socket
How can I make a variable work in more that one class? (Java)
Java - What are the layout managers available in awt.* and swing.* packages?
Reading ints from file and storing value to an array
random integers between 2 values
Maven -- is there a command to download the parent poms of all dependency jars?
Null Pointer Exception in Array when adding ActionListener
Hystrix Request Caching by Example
© Copyright 2017 Publishing Limited. All rights reserved.