Author Topic: Making a pathfinder by mapping bricks  (Read 1347 times)

Is it possible?

How can I create a "map" of all the bricks in the surrounding area?
I'm trying to figure out if it's possible to make a pathfinder bot, capable of navigating through obstacles.

Possible if you're a genius.

Pathfinding is not feasible in blockland.

I was kinda planning on doing this with just bricks and events.

Pathfinding is not feasible in blockland.

No not quite, if you have a good understanding of pathfinding mechanics + blockland and you put the effort/thought in, you can pull it off effectively.

Which reminds me that Flaw did exactly this. Placed 8x8 plates in a random formation and the bot ran through the shortest route from point A to B.

That's not literal pathfinding - that's pathfinding with the aid of waypoints. Entirely different, with waypoints it's easy.

Let me make some guesswork, I've never done anything like this before but this method should work.

Make all the raycasts have a range of about 1 - 2.5 studs.
Optional: Make the bot look at the target.
Do three raycasts from the eye point. (even two might work if its laggy)
If all three collide, turn 180 around. Do three more raycasts. If all 6 have collided, turn 180 degrees again and try to jump in the first three collided raycast directions, do raycasts again, if collided turn around and try and jump in the second 3 raycasts directions, if collided then the bot assumes defeat and pauses for about 10 seconds or so and tries again I guess.
If less than three collide, rotate the bot negatively by the summed true direction of all collided raycasts (eg. if you fired at -30, 0 and 30 and -30 and 0 collided then you would rotate negatively by -30 degrees)
Walk forward 1 - 2.5 studs.
Rinse and repeat.

sounds like its possible. but, there seems to be 1 problem with destiny's solution, that is that it goes in the first direction that is open. givin the right (or wrong) combination of directions, it may just loop forever. and also, it seems like that isnt pathfinding, its trying every possible direction until you finally get it righ, basically a brute-force attack.

sounds like its possible. but, there seems to be 1 problem with destiny's solution, that is that it goes in the first direction that is open. givin the right (or wrong) combination of directions, it may just loop forever. and also, it seems like that isnt pathfinding, its trying every possible direction until you finally get it righ, basically a brute-force attack.
Like Clockturns.
<makes waypoint 1, 2, 3, 4
"bot find something"
24242424242424242424242424242 424

sounds like its possible. but, there seems to be 1 problem with destiny's solution, that is that it goes in the first direction that is open. givin the right (or wrong) combination of directions, it may just loop forever. and also, it seems like that isnt pathfinding, its trying every possible direction until you finally get it righ, basically a brute-force attack.
I was referring to AI movement in general. Obviously you'd make it learn. If you want waypoint pathfinding look at this: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

When I made pathfinding it was based on a manually built nodegraph. It implemented something much like the algorithm Zack0Wack0 linked there, except mine went through the whole nodegrid keeping a list of the nodes it had been through for each iteration (to try to prevent infinite loops, they still occurred though) and the total distance.

The function calls itself at the new node with the current path recursively, though it had a whole bunch of schedule-and-callback shenanigans so the bot would enter a "thinking" state where it would begin pathfinding, and upon completion make a callback which pushes the path onto the bot and starts its movement.

So, borrowing the first frame of the Djikstra's algorithm runtime image from Wikipedia there:

Bot is at node 1, connected to 2, 3, and 6
Call function on nodes 2, 3 and 6:
findPath(bot,2,"1",7)
*not ideal path, not documenting*
findPath(bot,3,"1",9)
  Node 3, visited 1, distance 9
  Check connected nodes 1, 4, 6
  Visited 1, skip
  findPath(bot,4,"1 3",20)
    Node 4, visited 1, 3, distance 20
    Check connected nodes 2, 3, 5
    5 is target node, distance 6 for total 26 - return "26 3 4 5"
  findPath(bot,6,"1 3",11)
    Node 6, visited 1, 3, distance 11
    Check connected nodes 1, 3, 5
    5 is target node, distance 9 for total 20 - return "20 3 6 5"
findPath(bot,6,"1",14)
*not ideal path, not documenting*

Return distances of 26 and 20, 20 is lower so take path sent with 20 "3 6 5" - go to node 3
On reach node 3, go to node 6
On reach node 6, go to node 5
On reach node 5, call destination reached callback

Obviously this can get quite long hence all the schedule shenanigans, scheduling 10ms for every node, so a path to the destination with 5 nodes will literally return faster than a longer path as well (and then all the other "thinking" schedules are cancelled)

And also obviously, bots aren't always going to be standing right at a node - bots search for the nearest node to their location that they can raycast to, then begin the pathfinding process from that node while they walk there. You could also use four more raycasts to check a 'bounding' area of the bot from their current location to the node and see if it's really clear to walk, after doing a basic check so you do one raycast per non-feasible node and five total per potentially feasible node.

However, creating a pathfinder that will literally find paths on its own is more or less impossible - well, perfectly possible I guess, if you don't mind it freezing your game for several minutes while it pathfinds.
However you can always just set up a nodegrid for your bot deathmatchers or whatever.

It's perfectly possible to create a bot that can pathfind, but there are several important problems:

1. looping through the ServerConnection on a server with any number of builds will lag you for at least a second.

2. it won't find any players. Yes, there are aimbots that can; no, I'm not giving you one here.

3. raycasts don't work on the client's side.

It's perfectly possible to create a bot that can pathfind, but there are several important problems:

1. looping through the ServerConnection on a server with any number of builds will lag you for at least a second.

2. it won't find any players. Yes, there are aimbots that can; no, I'm not giving you one here.

3. raycasts don't work on the client's side.

This is all correct, but I'm not completely sure that we are restricting ourselves to client side code.

This is all correct, but I'm not completely sure that we are restricting ourselves to client side code.
Exactly right. Doesnt matter if its client-sided or not, whichever is simpler.
Im just going to scrap this anyway, would take too long to make, givin I could figure out how it would work.