Jump to content

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

A* "for dummies", in intuitive terms

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 SinusPi   Members   


Posted 24 January 2012 - 02:25 PM

I find few things as infuriating as algorithms that are always explained in pseudocode and graphs, while there are quite intuitive real-world similes, allowing for a much easier learning curve.

Such an example can be very easily used to describe Dijkstra's pathfinding, and expanded to A*. Those of you that wrote tutorials of your own, feel free to either correct my metaphor, or use it if you find it correct enough. Those of you that haven't quite grasped how those algorithms work, and are just struggling to make their pathfinder work at all, I hope this helps a bit. It's Dijkstra and A* for coders at kindergarten level. If you're an old pro, don't say it's obvious, it wasn't obvious for me until I pictured it like this.

So, here goes.

Consider a volcano, all teeming with lava, and a village near its base, pretty unlucky, if you ask me. The crater, full of white-hot lava, is the starting point; the village is the destination. We need to find out how fast can lava bring fiery armageddon to the village.

Now, in this virtual volcano, lava spreads in turns. At any moment in time, lava will pour from exactly one place onto spots around and below it - and the hotter the lava is, the easier it flows, so at any moment the hottest spot flows out to spots below... and the original spot cools completely, while the spots lava flowed onto retain some temperature: the closest, steepest spots were reached faster, so lava is hotter there than in far, slightly sloped areas. Of course, initially the crater is the only hot spot. In subsequent turns, lava from the hottest spots flows out... and out... cooling off, while the expanding edge is still pretty warm... until it reaches the village somewhere out there and reduces it to cinder. As soon as it does, we can see where lava flowed from - look at photos of lava flows, the flow direction is often easily seen! - so we can backtrack from the village onto the crater. Presto, the lava always took the easiest route, so it found the easiest path for us.

This is Dijkstra. Spots with hot lava = open nodes. Spots cooled = closed nodes. Terrain slope = cost. Lava temperature = cost of current path.

How do we burn this damn hamlet faster? Mind-bogglingly easy: we temporarily tilt the volcano towards the village, and push the village into a valley. Yes, the village is really out of luck this time. Yes, the lava can now flow differently, which may result in a longer path once we straighten the volcano and the village again (the terrain-bending was only temporary). But it should take it less turns to make crispy peasants.

A* right there. We have the volcano and the lava and everything, we just add a tilt, so that the lava has extra incentive to flow towards the village, rather than away from it. That's the heuristics magic.

Good luck burning those huts!

#2 calculemus1988   Members   


Posted 24 January 2012 - 02:31 PM

Yeah A* has saved a lot of villages so far, Dijkstra does not care about the poor people in the village Posted Image

#3 SinusPi   Members   


Posted 24 January 2012 - 02:33 PM

Um, actually, A* burns the silly hicks faster, even resorting to cheating :P

#4 Jaap85   Members   


Posted 25 January 2012 - 12:54 PM

great explanation Posted Image

My first game: Tycoon!


Please let me know what you think about it!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.