Jump to content

A* pathfinding in php


deano89

Recommended Posts

hey,

i have been searching the web for a while for examples of code that might be able to help me with making an a* pathfinding script..

all i need is a 2d map and for the algorithm to only move up, down, left and right.. no diagonal moves are allowed..

if anyone could help that would be awesome..

 

if you have any questions ill try and get back to you as fast as i can

 

thanks in advance,

deano

Link to comment
https://forums.phpfreaks.com/topic/212520-a-pathfinding-in-php/
Share on other sites

let S be start and E end point
x is walls

xxxxxxxxx
xxx x xxx
x x     x
x x x E x
xS   x xx
x       x
xxxxxxxxx

replace S with 0
xxxxxxxxx
xxx x xxx
x x     x
x x x E x
x0   x xx
x       x
xxxxxxxxx

in places near 0 put 1
xxxxxxxxx
xxx x xxx
x x     x
x1x x E x
x01  x xx
x1      x
xxxxxxxxx

in places near 1 put 2
xxxxxxxxx
xxx x xxx
x x     x
x1x x E x
x012 x xx
x12     x
xxxxxxxxx

end so on until is frespaces or you replace E

xxxxxxxxx
xxx x xxx
x x4567 x
x1x3x7E x
x0123x7xx
x1234567x
xxxxxxxxx

if you get E start with it and go to any place with number is smaler then number E
go to next smaler until number 0 (point S)

reverse path

There's been a few topics about this and I once created a semi-working path finding script when someone was asking about it.

 

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

 

It's not for PHP, but it shows you the basics and it shouldn't be too hard to convert it to PHP.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.