Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: A question on mechanics  (Read 902 times)

Xolroc

  • Bay Watcher
    • View Profile
A question on mechanics
« on: June 20, 2013, 10:54:13 am »

What, exactly, is the algorithm that DF uses for pathfinding?  I'm curious as to whether improvements are even possible while retaining universality.
Logged

Sizik

  • Bay Watcher
    • View Profile
Re: A question on mechanics
« Reply #1 on: June 20, 2013, 11:26:08 am »

A*, I believe.
« Last Edit: June 20, 2013, 11:27:54 am by Sizik »
Logged
Skyscrapes, the Tower-Fortress, finally complete!
Skyscrapes 2, repelling the zombie horde!

ORCACommander

  • Bay Watcher
  • [ETHIC:TORTURE_ELVES: PERSONAL_MATTER]
    • View Profile
Re: A question on mechanics
« Reply #2 on: June 20, 2013, 12:22:50 pm »

A heavily modified A* algorithm.

interactive examples: http://qiao.github.io/PathFinding.js/visual/
Logged

Xolroc

  • Bay Watcher
    • View Profile
Re: A question on mechanics
« Reply #3 on: June 20, 2013, 03:18:44 pm »

I know it's based around A*, but in what ways is it modified?  (also, that is an amazing little applet, I'm gonna play with that a bit)
Logged

ORCACommander

  • Bay Watcher
  • [ETHIC:TORTURE_ELVES: PERSONAL_MATTER]
    • View Profile
Re: A question on mechanics
« Reply #4 on: June 20, 2013, 05:20:16 pm »

for one there are weight values assigned to every tile. by default iirc the weight of any given tile is 25. if you start placing routes you get a whole wide range of values. and i  do not know if the A* algorithm takes into account a z axis to begin with.
Logged

Xolroc

  • Bay Watcher
    • View Profile
Re: A question on mechanics
« Reply #5 on: June 20, 2013, 05:54:54 pm »

If that's all, then I'd suggest Toady take a look at the Jump Point Search algorithm; it's an extension of A* that takes advantage of the fact that long straight paths are often possible, and only checks around obstacles.
Logged

Urist Da Vinci

  • Bay Watcher
  • [NATURAL_SKILL: ENGINEER:4]
    • View Profile
Re: A question on mechanics
« Reply #6 on: June 20, 2013, 08:13:37 pm »

Tile weights in an unedited game are:
HIGH 1
NORMAL 2
LOW 5
RESTRICTED 25

In a weight 1 area, A* will search out straight line paths first and not expand until it hits obstacles. HIGH traffic zones in hallways and staircases can really help out your FPS.

Xolroc

  • Bay Watcher
    • View Profile
Re: A question on mechanics
« Reply #7 on: June 20, 2013, 08:27:20 pm »

However, the advantage of JPS is that it treats long collections of free squares (hallways, rooms) as a single entity, and skips to the nearest place at which a turn would move closer to another feature/obstacle that it may need to path around.  This can provide large improvements in speed in very orderly systems, like the average player's fortress, and moderate improvements in randomized terrain.  The link earlier in this thread shows how A* works, but it also has other systems, including JPS, so you can see what I mean.
Logged

Mr. Palau

  • Bay Watcher
    • View Profile
Re: A question on mechanics
« Reply #8 on: June 20, 2013, 08:43:43 pm »

However, the advantage of JPS is that it treats long collections of free squares (hallways, rooms) as a single entity, and skips to the nearest place at which a turn would move closer to another feature/obstacle that it may need to path around.  This can provide large improvements in speed in very orderly systems, like the average player's fortress, and moderate improvements in randomized terrain.  The link earlier in this thread shows how A* works, but it also has other systems, including JPS, so you can see what I mean.
I hope the pathing program uses something like this already. Please good god Armok.
Logged
you can't just go up to people and get laid.

Xolroc

  • Bay Watcher
    • View Profile
Re: A question on mechanics
« Reply #9 on: June 20, 2013, 10:04:09 pm »

If it uses A*, then no it doesn't.  But remember, it's not as simple to compute as you think.  There are more computations in A*, but they're faster than the more complex but fewer ones that need to be done in JPS.  So the speed increase isn't as great as you'd expect.  Look at the timer in the bottom left of that applet.
Logged

Di

  • Bay Watcher
    • View Profile
Re: A question on mechanics
« Reply #10 on: June 21, 2013, 04:59:50 pm »

Well, we don't know much of the inner workings of the game. Toady probably has modified that A* beyond recognition so that simple version from applet does not represent it well.
There was a couple of threads on suggestion board about JPS, though it's unknown whether Toady has seen them.
Logged
Quote from: Creamcorn
Dwarf Fortress: Where you meet the limit of your imagination, moral compass, sanity and CPU processor.
http://www.bay12forums.com/smf/index.php?topic=103080.0 Fix sober vampires!
http://www.bay12forums.com/smf/index.php?topic=91442.0 Dwarven Cognitive Science