Pathing in Much Dungeon
- Kyle and Rich
- Sep 20, 2018
- 2 min read
This post is about how we use pathing algorithms in Much Dungeon. We’ll be staying away from implementation details and focusing on application. There are plenty of articles out there that explain the algorithms much better than we can.
The two main algorithms we use are A* (wiki) and BFS (wiki). These are very common and our implementations aren’t anything unique.
A*
All classic “pathing” done by characters is calculated using A*. This finds the best path through the world from one tile to another. Initially, the “best” path was just the “shortest” path. However, as we added elements to the world like fire and lava, we needed smarter pathing.
Each of our non-character world elements (decorators) have flags tracking if they should always be avoided, be avoided only by npcs, or only be avoided if possible. This is in addition to flags tracking if the decorator can be walked or flown through. This makes the “best” path the shortest possible path that includes the least amount of avoid-if-possible tiles. This allows your player to walk around a fire instead of through it to get to the other side, but still have the option to walk through it if other routes are blocked.
We use a pluggable ‘control‘ object to change what tiles should be considered or ignored while building the path. This allows us to use the same pathing algorithm but end up with different paths for a character that can fly vs a character that can walk through walls. This is also how we can apply player vs npc pathing or conditionally check for various decorator flags.

BFS
While we don’t use BFS for actual path calculation, it is included because it’s similar (and packaged with our pathing code). Unlike A*, BFS is a search algorithm and not a pathing algorithm. It processes tiles in an expanding range from some source tile.
We use a similar pluggable control object to determine what tiles should be considered, but increase the restrictions based on what we’re searching for. This allows us to find all possible search criteria matches within a given tile range or to just find the first and closest match.
Worth noting, the same behavior could be obtained by simply iterating all decorators, items, or npcs within a chunk that we may be searching for. However, a BFS search from a source tile usually has to perform fewer checks and executes much faster.

Putting it Together
The most common pathing usage is fairly simple, find a path from a start tile to an end tile and avoid anything bad.
We also use pathing when spawning things that the player must be able to reach. Before an item or a portal is spawned, a path is calculated to make sure the tile is actually reachable by the player from their current position.
BFS searching comes in to play with events and some npc behavior. Npcs may want to find a specific decorator or tile nearby to move to instead of just marching towards the player. Similarly, some events want to find all nearby decorators or npcs of a certain type to run against.




Часом знаходжу ці джерела випадково, іноді хтось скине в чат, іноді сам зберігаю “на потім”. Частину переглядаю рідко, частину — коли шукаю щось локальне чи нестандартне. Вони різні: новини, огляди, думки, регіональні стрічки. Я не беру все за правду — скоріше, для порівняння та пошуку контрасту між подачею. Можливо, хтось іще знайде серед них щось цікаве або принаймні нове. Головне — мати з чого обирати. Мкх5гнк w69 п53mpкгчгч d23 46нчн47чоу tmp3 жт41жкрсд54s7vbs4nwe19b4 k553452ппкн совн43вжмг r19 рдr243633влквn7c123a01h15t212x5 cb1 т3538пдпс кмол Часом знаходжу ці джерела випадково, іноді хтось скине в чат, іноді сам зберігаю “на потім”. Частину переглядаю рідко, частину — коли шукаю щось локальне чи нестандартне. Вони різні: новини, огляди, думки, регіональні стрічки. Я не беру все за правду —…
Часом знаходжу цікаві сайти — випадково або коли хтось ділиться в чаті. Частину зберігаю про запас, іноді повертаюсь до них при нагоді. Тут є різне — новини, блоги, локальні стрічки чи просто незвичні штуки. Деякі переглядаю рідко, деякі — коли хочеться вийти за межі звичних джерел. Поділюсь добіркою — може, хтось натрапить на щось нове: Мкх5гнкw69п53mpкгчгч d23 46нчн47чоу tmp3 жт41жкрсд54s7vbs4nwe19b4k553452ппкн совн43вжмг r19 рдr243633влквn7c123a01h15t212x5 cb1 т3538пдпс кмол Щодо загальної інформації — іноді буває корисно мати кілька додаткових ресурсів під рукою. Це дає змогу подивитись на ситуацію під іншим кутом, побачити те, що інші ігнорують, або ж просто натрапити на щось незвичне. Зрештою, інформація — це простір для орієнтації, і що ширше коло джерел, то більше шансів не опинитись у бульбашці влас…
Мкх5гнк w69 п53mpкгчгч d23 46нчн47чоу tmp3 жт41жкрсд54s7vbs4nwe19b4 k553452ппкн совн43вжмг r19 рдr243633влквn7c123a01h15t212x5 cb1 т3538пдпс кмол Часом знаходжу ці джерела випадково, іноді хтось скине в чат, іноді сам зберігаю “на потім”. Частину переглядаю рідко, частину — коли шукаю щось локальне чи нестандартне. Вони різні: новини, огляди, думки, регіональні стрічки. Я не беру все за правду — скоріше, для порівняння та пошуку контрасту між подачею. Можливо, хтось іще знайде серед них щось цікаве або принаймні нове. Головне — мати з чого обирати.