I have a little coding puzzle that I can't solve

Blitz3D Forums/Blitz3D Programming/I have a little coding puzzle that I can't solve

GIB3D(Posted 2010) [#1]
I'm trying to make my own pathfinding system but am stuck because of this. I can't wrap my mind around this one. How would you do this in code?

The first number is the starting pathnode

1,1,1
1,2,1
1,3,1
1,1,2
1,2,2
1,3,2
1,1,3
1,2,3
1,3,3


The size of that will depend on how many nodes there are. Each number is a node_id. Once this puzzle is solved I will be able to make it faster by stopping it from adding on more numbers if there is a duplicate number.

Also, I tried searching on google but I couldn't find anything mainly because I'm not sure what to search for.

Just to show you what I'm working with, here is the code.



Jiffy(Posted 2010) [#2]
I'm not sure what you're doing, but I think you're going about it the wrong way. You're mapping out an exponential growth in complexity each time you add a node.
You may need to look at the problem differently- or at least find a way to quickly cull invalid nodes.


GIB3D(Posted 2010) [#3]
Well at the moment I need to be able to make a big list of every possible path an object can take first. Each line would be the Type called Path. Each number within the Path is the Type Element which stores its parent node. Then after I'm able to do that I'll stop it from creating the paths if it finds a duplicate node in the list. What I originally had was 3D but sometimes I have to start fresh so I can try to actually code what I need instead of worrying about how it looks on-screen.

This is partly where I'm getting some of my information http://ai-depot.com/Tutorial/PathFinding.html

The difference between what I'm doing and what they have is Neighbors. None of my nodes are connected because I do not know how to find the Neighbor of a node and connect them dynamically.


Jiffy(Posted 2010) [#4]
I find that tutorial confusing. I suggest

http://www.policyalmanac.org/games/aStarTutorial.htm

about 7 versions exist here:

http://blitzbasic.com/codearcs/codearcs.php?cat=6

search for 'path'


xlsior(Posted 2010) [#5]
A full map of possible nodes does get exponentially large -- depending on how you define a 'node' (waypoint? Walkable terrain tile?) the total map could end up being gigabytes in size, or even larger.


GIB3D(Posted 2010) [#6]
I found that policymanac.org tutorial extremely confusing when trying to change anything in it. It's a grid based system which I don't want and it does some funky Binary Dump stuff that I don't completely understand. I'm wanting the pathfinding system to be more like how Half-Life 2 and Unreal Tournament 3 do it. If you've ever used either of their map editors you would know that they both use User Placed Path Nodes. Without the path nodes, the AI are extremely dumb when it comes to moving around.


Jiffy(Posted 2010) [#7]
Node paths are artificial & only work on fixed maps with specific game dynamics. Better & faster if that's what you need, but prone to occasional issues & ignorant to new game dynamics. Try spawning a vehicle on a map not designed to have one & block off a path- see what the AI does. I hope it can tell, but I doubt it. UT3 pathing used to be pretty buggy- don't know if it's cleaned up or not.

Anyway, try modifying

http://blitzbasic.com/codearcs/codearcs.php?code=968
or
http://blitzbasic.com/codearcs/codearcs.php?code=1825

as starter waypoint systems. puki did the first one & he's about- maybe he'll answer q's you have about it.

You gonna eat that thing or what?


GIB3D(Posted 2010) [#8]
I know node paths are on fixed maps and can't be put in later. I also noticed in the Unreal Editor that you can see the node's connections before you even test the map. So in some way, I'm probably going about this wrong because I "need" to connect the nodes. I'll take a look at the links you posted.

Edit:
I took a look at the links. The first one is good, the second one I have already seen but thanks anyways. I'm going to code in a neighbor system now and hopefully I can actually get some good pathfinding working. I guess what I'll do is limit each node to finding Four nodes near it.

Pseudo Code
Type Node
Field T_Neighbor.Node[3]
End Type


I'll just add that into my code and work on it from there and post back here if I get it working.


GIB3D(Posted 2010) [#9]
:)

It's not much yet but it's a simple neighboring demo. The big red block is literally a block. A LinePick checks if you can safely travel straight to that node without hitting things. The LinePick is also effected by nodes too. Nodes are pickable so that you don't have a lot of nodes in one place being picked.

Use keys 1 through 0 to change which neighbors are displayed.
The 0 key is for the first node. Don't blame me, blame ASCII.



I can see the end in sight :D All I have left now is to code it to make it branch out through the neighbors and keep going till it finds the goal node. It will delete any path that finds a node that has already been added because that means it was looping back to a node it has already seen. For example...
Node1 to Node2 to Node3 to Node1


lo-tekk(Posted 2010) [#10]
Have a look right here: http://www.blitzbasic.com/Community/posts.php?topic=73941#832575

[edit]Sorry, the link has gone. Reuploaded here:

http://www.box.net/shared/kgzoydu3ds

Maybe you can make a good use out of it.


Knight #51(Posted 2010) [#11]
You should definitely try ordered lists or trees for AI path finding nodes.


GIB3D(Posted 2010) [#12]
I'm already doing "orderly lists".. or "trees"... I think.. heh. I'm using Types to store all the information. At the moment I have some of it working but I need to seriously debug it because I have done some things wrong but it does work because I before I broke it some more, I saw it work ;)


GIB3D(Posted 2010) [#13]
I got it working mostly. Sometimes it can't find a path even when there is an obvious route but once again I probably coded a few things wrong.

Controls:
Press a number to find a path to that node
0 = 1
1 = 2
3 = 4
etc...

Left and Right arrow keys turn the camera
Pressing T toggles the info view from seeing Node info to Path info

Sometimes it doesn't show the full path.. no idea why.

There are 10 nodes and more can be added in the CreateNodes() function




GIB3D(Posted 2010) [#14]
I found a nice video for pathfinding. It shows almost the same exact way I'm doing it. http://www.youtube.com/watch?v=WC1Po5rWXr0