Jump to content

Navigating mazes

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
On our first contest we had this problem here that dealt with finding the optimal distance from one letter to another. I have absolutely no idea how to do this, but these problems keep coming up, and I was curious as what things I should look into, to better understand this. I'm not going to get very far if I don't learn how to go about these.

Thanks for the help.

chili :)

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
You'll have to employ some logic. Try the routes, and find the best one.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
My approach:
Store the map in an array with an array of int of the same size.
Start out the int array with values of -1.
Seed the initial location with 0.
Then update all reachable locations that are adjacent to 0 with 1's.
Then update all reachable locations that are adjacent to 1's and are -1 to 2.
Repeat until you reach your next waypoint.
Reset all values except your current waypoint to -1.
repeat. the above process to reach your next waypoint.

The idea is that if you mark all locations based on their distance from a given point, you have rings of distances spreading out. Exploit that.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Thank you Winged.

That's very helpful.

#5
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
I would do it this way:
1. build a table of distances between marked points, based on a simple recursive algorithm.
2. perform addition.

the algorithm to find the optimum distance between two points. the function takes the distance so far n, and two points, as well as an array of the previous points
1. if point is a wall, return infinity. (biggr than all others: will never be the minimum except when there is no route.)
2. if at destination, return n.
3. if current point is in list of previous points return infinity.
4. find optimum distance from points above below, left and right, passing n+1.
return minimum of those.

what do you think?
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz