deano89 Posted September 4, 2010 Share Posted September 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/212520-a-pathfinding-in-php/ Share on other sites More sharing options...
sasa Posted September 4, 2010 Share Posted September 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/212520-a-pathfinding-in-php/#findComment-1107208 Share on other sites More sharing options...
JasonLewis Posted September 4, 2010 Share Posted September 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212520-a-pathfinding-in-php/#findComment-1107210 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.