About pathfinding in JS API

For code related discussions and questions

About pathfinding in JS API

Postby Prot » 19 Dec 2017, 06:33

Try to optimize the performance of the bot with the army. There are several thoughts about this.
I think we need a couple of new features in the JS API.
Firstly I would like to get an array of coordinates from pathfinding from point A to point B.
Secondly, I would like to have an easy function DROID_MOVE without pathfinding it would be possible to optimize the route, as well as to optimize the army during the battle (each injured units behind to keep a stronger army, or keep to the special formation of the army).
As I understand it, in the moment, each order of each unit still causes pathfinding algorithm, even in the case where it is not needed(at short distances).
And where it is really needed inside the algorithm of the bot, we have no access to it at all.
And third. I think it would be nice to make a function that would order the entire group. Because the loop is inside qtscript seems much slower than if there was a loop inside C++ functions, foreach order unit.

PS before somewhere already heard that there is no access to the pathfinding because it would have greatly slowed down the work of the bot. But pathfinding and so is called every order, even when not needed. And if I had access to an array of pathfinding could be much better optimized code bots, cause once him and then orders without calling pathfinding to follow the coordinates.

PSS So... somthing like:
Code: Select all
getPathfinding(propulsion, x1,y2,x2,y2); //Return array of coorinates
groupOrder(group, order, location); //Cycles trough every units outside JS
droiLightOrder(droid, order, location); //Order without call pathfinding
//and maybe
groupLightOrder(group, order, location); //Cycles trough every units outside JS wihout pathdinfing


By the way, it also would have solved the problem, as pathdinfing ignores buildings, it would be possible to check through the array of stands in the way of a tree or a building. Thus, to be sure, for example that the path to the desired resource is not blocked by trees or something else that doesn't notice pathfinding, at the JS side.
User avatar
Prot
Trained
Trained
 
Posts: 96
Joined: 29 Nov 2010, 12:41

Re: About pathfinding in JS API

Postby Darkling » 19 Dec 2017, 06:55

Related to the path finding it would be good if there was a function that would return how much distance a unit would actually travel (given a particular propulsion) between points a and b accounting for impassable terrain between them and maybe returning a set of way points for the route as well.
User avatar
Darkling
Rookie
Rookie
 
Posts: 18
Joined: 07 Feb 2016, 00:45

Re: About pathfinding in JS API

Postby Per » 19 Dec 2017, 09:29

It is something I've thought about occasionally, without coming to any good solution.

The main problem is that path-finding is done asynchronously, to avoid causing lag. So if you do a call eg giveMeAPathTo(droid, x, y) then you will get an answer in a later frame, not within the same execution of the script. So you'd have to carry on with that logic with a later call from eg eventPathFindingDone(droid, path) or something like that.

Exposing the path queue to JS and allowing changes to it or manually building your own path queue for micromanagement of droids on the battlefield, is probably more straight-forward.

There is no benefit performance-wise to calling path-finding for entire groups at a time. Doing some kind of 'group move' is something we should have, and it could help performance too, but the main benefit I think would be staying in formation. However, I think this is far from trivial to do.

Path-finding does not ignore your own buildings - and it can be told whether or not to ignore enemy buildings (on the assumption that they will be destroy en route). This kind of configurability is not exposed to scripts yet, though, since it is all hidden behind orders.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3696
Joined: 03 Aug 2006, 19:39

Re: About pathfinding in JS API

Postby MIH-XTC » 19 Dec 2017, 16:59

I don’t know anything about pathfinding or pathfinding in WZ but I do know that modern navigation systems usually use an algorithm called bidirectional A*

The latest and greatest I think is called NBA* (New Bidirectional A*) if you want to know more about how path finding algorithms work.

Paper regarding NBA*
http://repub.eur.nl/pub/16100/ei2009-10.pdf
MIH-XTC
Trained
Trained
 
Posts: 209
Joined: 31 Jan 2014, 07:06

Re: About pathfinding in JS API

Postby Prot » 19 Dec 2017, 17:44

MIH-XTC wrote:I don’t know anything about pathfinding or pathfinding in WZ but I do know that modern navigation systems usually use an algorithm called bidirectional A*

The latest and greatest I think is called NBA* (New Bidirectional A*) if you want to know more about how path finding algorithms work.

Paper regarding NBA*
http://repub.eur.nl/pub/16100/ei2009-10.pdf

It does not help. Implementation of this algorithm on the JS side will cost performance is quite expensive.
User avatar
Prot
Trained
Trained
 
Posts: 96
Joined: 29 Nov 2010, 12:41


Return to Coding