2019-08-03 21:31:07 (edited by amerikranian 2019-08-03 21:34:41)

So, I'm not gonna ask how to create a Pathfinder, I think I already have that established, and I think it actually works. My problem is that I am not too sure how to use the damn thing.
I've tried to have each enemy have a path that is related to enemy vs. player's coordinates, key being tried. It didn't work so well, resulting in the game crashing more than anything. However, I cannot have a centralized path do to the inability to know where enemies spawn (I would like them to pop up anywhere on the map and still be able to find the player). How would I go about accomplishing my goal? Do I create 2 paths, one starting at 0 and one starting at the max edge of the map and update them as the player moves? This might make sense, except you have to consider that the map may be more than 400 squares wide and tall so... yeah. I am just a bit stomped. Also, I forgot to mention, but I'm still doing all this in Python, though I feel like this is more of a conceptual question rather than code.
My second question is a bit more interesting. What I've found for pathfinder (a-star algorithm) seems to be focused on 2D grids only. I feel like I can at least attempt to remake it so that it works with 3D as well. The question is... is there something better out there that is designed to include the x, y, and z axes? Anything I should be aware of if I was to convert the thing to 3D?

2019-08-03 23:05:41

Pathfinding... thats a rather comprehensive topic.
A star is a rather unintelligent, simple approach. It should work properly in 3D as well, if properly implemented that is. Due to it not being utterly intelligent, it is not the fastest approach of finding paths though. The implementation can and will make the difference though, even a more intelligent algorithm can be slower than A star if the implementation is worse. I can just recommend to implement your pathfinding in a more low-level language like C (with the help of Cython). The reason is simple:
I'm developing a grid-based 2D tactical turn-based game right now which works with like 30+ enemies on a 50 x 50 map and like 10 playable characters. All enemies have to find a path from their given location to all reachable players, calculating their path on certain unmovable tiles thus a way needs to be found that doesn't pass this certain tile, and a few more obstacles. I was using the path_finder class provided for BGT and even though I added in a caching mechanism to prevent me from re-calculating the very same paths over and over again, it still took a very long time to calculate the proper movements of the AI. I then took a step forward and re-implemented A star in C++, polishing the algorithm through multiple revisions, until you now can't feel the delay anymore, even with loads more enemies and playable units on a much larger map.
Due to several implementation problem in Python, really efficient algorithms in Python will run much slower than in low-level languages. Thus, if you're planning to reduce the calculation time to prevent exhaustive waiting times if many units have to be controlled, think about implementing the path finder separately and access it externally from Python.
Best Regards.
Hijacker

2019-08-04 00:18:46

Interesting. Unfortunately I do not know c or c++, so the best I'm gonna get is Cython. Thanks for the tip, though

2019-08-04 08:35:30

if you are asking me, go for stearing behaiviours.
things like persue, evade, etc, which can make your enemies more intelligent.

2019-08-04 09:28:51 (edited by magurp244 2019-08-04 09:34:02)

I do have some experience with this, largely using a 2D grid implementation of A star with 8 cardinal directions, optimization can be a bit tricky, especially when scaling or using flocking systems. But part of it can be handled with compartmentalization and sectorization. The implementation used heaps, though Numpy could be another option, with maps that could theoretically scale upwards of 10,000 by 10,000, I was going to further optimize it by breaking down the maps into discrete sector chunks as meta waypoints to reduce load.

For example lets say you have a map thats 320 by 320 tiles, which could take a long time for a pathfinding algorithm to traverse. You take that map and break it into a hundred 32 by 32 Sectors, with each sector containing 1024 tiles. So, if you want an AI to move from one end of the map to another, you first pathfind across the "meta" map of 100 sectors from the AI's current sector to the sector where your destination is, then you pathfind a local path from the AI's current position in the current sector to the next sector along that "meta" path, then caculate another local path through that sector to the next, and so forth and so on. This way your only calculating paths in smaller chunks as you go, the only down side is if you can't reach some adjacent sectors in the sector path because of obsticals in the local sector, like walls for example, but there are ways to optimize around that abit.

Another way you can optimize pathing is to recycle paths when moving in groups, so if Unit A and Unit B are going the same direction, you can share the same pathing data and offset their positions. If you want to get fancy, you could also look into Flow Fields which were used in Supreme Commander 2 and Planetary Annihilation, there's a dev talk [here] about it. Its similar to the picking a set direction and it steering itself towards that goal based on weighted collision data.

As for finding the player, one way could be to implement a search pattern algorithm so they comb the areas systematicallyfor the player, or follow some form of behavior, or you could "cheat" and just pass the players current coordinates either when they spawn or on each cycle so they can home in on them.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-08-17 02:41:50

Is it true that bgt uses A* for path finding?

2019-08-17 04:10:59

I didn't even know BGT had pathfinding capabilities. I'd recommend the AStar algorithm, though I'm not very experienced with pathfindig myself (I do need to familiarize myself with it more...).

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-08-17 05:33:45

@bgt lover: how should we know? BGT's source is closed after all. But judging from its performance, its probably A*, and it seems to be a rather bad implementation, considering that its using C++ under the hood.
Best Regards.
Hijacker

2019-08-17 23:26:47

Here is my simple AStar pathfinder in Cython.
I won't guarantee it works, I'll just say it worked for me.
Feel free to change it as much as you like.
It's got one class, pathfinder.
setup_map(int max_x, int max_y)
This initializes the internal map to be max_x by max_y units large. The internal map is 2D by the way.
set_terrain(min_x, max_x=min_x, min_y, max_y=min_y, type)
Allows you to modify entire areas of the map to have the terrain type and returns the number of squares who's type was changed.
The type determines how likely the computer will step in it, with 0 being the most likely, and 10 being completely impassable.

find_path(x1, y1, x2, y2, allow_diagonal=False)
Try to search a path from x1, y1 to x2, y2 through the map that is currently set up.
Returns a list of (x,y) tuples on success, (the first one being the starting location), each (x,y) tuple being a set of x,y coordinates, or an empty list if it didn't find a way.
Allow diagonal lets you set weather or not to allow moving in diagonal directions.
This class uses numpy, so make sure to install it.
The only other thing of interest is maparray, which is the 2D numpy array representing the map.
You can change single coordinates in the map and maybe more, if you mess around with it.
Here's the link.
I wasn't planning to share this, so there are no docstrings or such.
https://www.dropbox.com/s/ac2qe6xfizmoq … r.pyx?dl=0

Oh, and hope you have
a compiler! tongue