Artificial Intelligence Tools Extension (Beta Release 8)

merrak

  • *
  • Posts: 2738
To draw a path (I'm assuming you mean a path computed using the pathfinding tool?), then all you need to do is loop through the list that is returned. Use the "as list of nodes" option. Each item in the returned list is a sublist with data for the node's position, name, and cost. Entry 0 and 1 will be the row, col coordinates of the node respectively.

Here's an example that will a dotted line along the path.

Code: [Select]
(Drawing event)
Set fill color to (color)
Transform to screen coordinates
For each item in (returned path)
    Fill circle of radius 3 centered at x: ((get entry #1 from item) + .5)*tile width    y: (get entry #0 from item) + .5)*tile height
End For

I'll need clarification on what you mean by connecting the tiles. Did one of the blocks cause a null error? If so, for what platform? Make sure you're using the latest release (Beta Release 7). There was a platform-dependent error that was reported and fixed.

AdamJ

  • Posts: 19
I've hit a little snag while using this (awesome) extension.  I created a scene behavior that creates a graph and then culls nodes out based on collision meshes of static actors; environment art that need to be avoided (basically a forest).  Then I tried to add an actor behavior to my actors so they'd use that graph to chart their course through the forest.  As I discovered, though, the graph isn't really an attribute and can't be accessed by the actors. 

So what's the best way to approach this scenario?  It seemed wasteful for each actor to generate their own copy of the graph, but maybe that's what I'm supposed to do?  Or is there a way to encapsulate or "attributify" the graph from the scene behavior so the actors can see it?

Many thanks to anyone for any guidance, and thanks to Merrak for the great extension. Thumbs up.

UPDATE: I'M AN IDIOT.  My graph is named "navmesh".  My actors were trying to chart a path on "navmash". Thus the latest example of wrestling with a problem for 2 or 3 hours and figuring it out 5 minutes after asking for help.

« Last Edit: May 21, 2017, 05:30:14 am by AdamJ »
Chickadee Games : www.chickadeegames.com

merrak

  • *
  • Posts: 2738
Sounds like you answered your own question ;)

FYI, the graph can be exported to a list attribute, but you can't use the resulting list to run any graph-based calculations (like pathfinding).

yoplalala

  • *
  • Posts: 1632
In Build 9828, AI Tools don't work anymore because of layers.

Must have to do with https://github.com/Stencyl/stencyl-engine/commit/7f340651b4fabd036f1a0627a42335b46381ec20

You can do something like this
#if (openfl <= "6.0") r, c #else  engine.getLayerById(-1) #end

« Last Edit: March 28, 2018, 01:21:39 pm by yoplalala »

merrak

  • *
  • Posts: 2738
Thanks for the notice. I guess something changed between Build 9751 (what I'm using) and 9828. I'll get an updated version up.

SirCrocketz

  • Posts: 24
Hey merrak! Just curious if you have an eta for the update on your extension. I use it pretty extensively in my current project :)

Also, Is there any kind of smoothing built in? Or know of an easy way to achieve smoothing the path results?

merrak

  • *
  • Posts: 2738
Should be updated now :)

Check 'Beta Release 8' on archives page if the main link hasn't yet updated.

Also, Is there any kind of smoothing built in? Or know of an easy way to achieve smoothing the path results?

I'm not sure what you mean by smoothing the path results. Did you see the 'merge path' block?

Quote
Optimizes a list of nodes. mergePath searches for collinear nodes, eliminates interior nodes, and preserves only the endpoints.

SirCrocketz

  • Posts: 24
Awesome! I'll download it right away! Thanks so much for the quick response :)

This image explains what I mean by smoothing (may be incorrect term). http://i.imgur.com/6UIRisc.png
I'll play around a bit to see if I can figure it out. Thanks again!

merrak

  • *
  • Posts: 2738
There isn't anything provided out-of-the-box that will produce the image on the right. The merge path function will get you partway there by eliminating all of the nodes except where the direction changes. One thing you could do to further optimize the path is search through the nodes that remain after merge path and see if any can be skipped. Something like this:

Code: [Select]
1. path = (Compute the path from Point A to Point B)
2. path = (Use mergePath to optimize the path)
3. Loop through each node n in path, starting from Point B and working backward to A
    3A. If no obstacle exists between Point A and node n then delete all nodes in the path
        from the node after Point A to the node just before n. Exit loop
    3B. Otherwise, continue

SirCrocketz

  • Posts: 24
Hey Merrak!

Quick question. If there should be two paths of equal cost, is there a way to return both of them? I'm trying to randomize my pathfinding a little bit.

merrak

  • *
  • Posts: 2738
Hey Merrak!

Quick question. If there should be two paths of equal cost, is there a way to return both of them? I'm trying to randomize my pathfinding a little bit.

You'd have to modify the algorithm. The principle sounds simple enough. (See https://stackoverflow.com/questions/10738478/how-to-find-all-the-shortest-paths-by-using-a-algorithm). It's been a while since I've looked at the A* code, but I have a feeling making the change would necessitate some reworking of how the code is organized... placing this problem neatly into the "simple in theory, tedious in application" category.

In certain applications, it'd be easier to just add some variation to the edge costs. For example, in my game I'm considering enemy actors pursuing the player. Adding variation to the edge costs would result in the enemy actors not necessarily taking the most optimal path, but would still take a "good" path. That sort of behavior seems more realistic to me. People and animals make assumptions and make mistakes. Not sure what specific problem you're trying to solve--just wanted to throw the idea out there.

dtishin

  • Posts: 89
Hi, I've tried to install the AI Tools extension but it doesn't show up. I closed and re-opened the project (and Stencyl), no effect.
It does show under Setting > Extensions, but nowhere else (see attached screenshot).
I'm using the official Stencyl version from the Download page (3.4.0 beta 4, b9300, 2017-02-14).
Any leads? Will really appreciate any help. I'm making an RPG, and pathfinding is obviously a critical thing :) Thanks!

dtishin

  • Posts: 89
Sorry for the false alarm, found a corresponding section of custom blocks now.

dtishin

  • Posts: 89
Hi Robert,
The pathfinding AI works great, which helps my project tremendously!
Still, I found it can generate errors in my specific case.
As I understand, it has to do with my code rather than with your tool, but I'd appreciate any leads.
The bug seems to be triggered when my Avatar collides with the detection sensor and the NPC is itself collided with a tile at the same time, but I'm not entirely sure.
Here's the error message it generates (also see attached as a screenshot):

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at AStar$/bestPath()[C:\Users\Demid Tishin\AppData\Roaming\Stencyl\stencylworks\engine-extensions/ai-tools/AITools.hx:1291]
   at AITools$/findPath()[C:\Users\Demid Tishin\AppData\Roaming\Stencyl\stencylworks\engine-extensions/ai-tools/AITools.hx:196]
   at MethodInfo-6771()[Source/scripts/Design_9_9_NPChackandhug.hx:776]
   at com.stencyl.models::Actor/innerUpdate()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/models/Actor.hx:1530]
   at com.stencyl::Engine/update()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2479]
   at com.stencyl::Engine/postUpdate()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2618]
   at com.stencyl::Engine/onUpdate()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2611]

I tried running the game in the debug mode, but it constantly requests Visual Studio, which I already have (up-to-date version) so I have no clue how to debug it.
Here's the game project file if you'd like to take a quick look: https://www.dropbox.com/s/q1cs9x3oxwuw8wh/Attack%20Talk%20Sneak.stencyl?dl=0
And here's a recorded video (the error message does not show on video since it's generated over the active Adobe Flash window) https://www.dropbox.com/s/q1cs9x3oxwuw8wh/Attack%20Talk%20Sneak.stencyl?dl=0

Thank you very much!

merrak

  • *
  • Posts: 2738
Hi Robert,
The pathfinding AI works great, which helps my project tremendously!
Still, I found it can generate errors in my specific case.
As I understand, it has to do with my code rather than with your tool, but I'd appreciate any leads.
The bug seems to be triggered when my Avatar collides with the detection sensor and the NPC is itself collided with a tile at the same time, but I'm not entirely sure.
Here's the error message it generates (also see attached as a screenshot):

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at AStar$/bestPath()[C:\Users\Demid Tishin\AppData\Roaming\Stencyl\stencylworks\engine-extensions/ai-tools/AITools.hx:1291]
   at AITools$/findPath()[C:\Users\Demid Tishin\AppData\Roaming\Stencyl\stencylworks\engine-extensions/ai-tools/AITools.hx:196]
   at MethodInfo-6771()[Source/scripts/Design_9_9_NPChackandhug.hx:776]
   at com.stencyl.models::Actor/innerUpdate()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/models/Actor.hx:1530]
   at com.stencyl::Engine/update()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2479]
   at com.stencyl::Engine/postUpdate()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2618]
   at com.stencyl::Engine/onUpdate()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2611]

I tried running the game in the debug mode, but it constantly requests Visual Studio, which I already have (up-to-date version) so I have no clue how to debug it.
Here's the game project file if you'd like to take a quick look: https://www.dropbox.com/s/q1cs9x3oxwuw8wh/Attack%20Talk%20Sneak.stencyl?dl=0
And here's a recorded video (the error message does not show on video since it's generated over the active Adobe Flash window) https://www.dropbox.com/s/q1cs9x3oxwuw8wh/Attack%20Talk%20Sneak.stencyl?dl=0

Thank you very much!

Hi,

This is line 1291, the one that your game is complaining about

Code: [Select]
graph.nodeAt( startRow, startCol ).g = 0;
where startRow and startCol are the tile coordinates you specify in the "find path" block. If the graph doesn't exist then you would get an error in line 1287, so the only remaining possibility is that there is no node at the coordinates you specify.

I don't provide much error checking with the AI tools, so what you can do to catch this condition is use the "node exists at R, C" block to make sure you're running path finding on a valid position. If a node doesn't exist at R,C, maybe have it print a warning so you'll know the problem is with your graph.

I suspect that's the issue. At the moment I'm not able to verify it myself by downloading your project. My Stencyl has a modified engine, so I'd have to revert back to "vanilla Stencyl" to test it.

You can also modify the AITools.hx file to make that function more robust. Add this to line 1291, right after the line "openSet.push( graph.nodeAt( startRow, startCol ) );":

Code: [Select]
if ( graph.nodeAt( startRow, startCol ) == null )
{
trace( "Warning: There is no node at (" + startRow + "," + startCol + "). Returning empty array." );
return new Array<Dynamic>( );
}

This will give you a safer mode of failure: the game shouldn't crash, and you'll get an error in your log viewer.