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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.