Hello people !!
I'm having some problems determinating a best path.
I'll explain in more detail by giving some examples
mapdata:
db 1,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0
db 0,0,9,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0
this is my map, where 0 is land (you can just walk on it), 1 is the position of the player, and 9 is the position where you click with the mouse.
As soon as you click with the mouse the best/shortest path is displayed with an X on the screen, like this:
mapdata:
db 1,0,0,0,0,0,0,0,0,0
db 0,x,0,0,0,0,0,0,0,0
db 0,0,x,0,0,0,0,0,0,0
db 0,0,9,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0
In this situation the best path is DR(downright), DR, D
How is this calculated ?
The computer first looks at the starting postion (0,0) and then at the ending position (2,3)
then the computer looks at dx (2-0). is this positive then the first step should be to the right.
then the computer looks at dy (3-0). is this positive then the first step should be down.
so the first step should be down and right. DR.
ok, now comes the hard part, lets take this example:
mapdata:
db 0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,T,0,0,0,0,0
db 0,0,1,0,T,9,0,0,0,0
db 0,0,0,0,T,T,T,T,T,T
in this situation the player start at (2,4) and has to go to (5,4), but there are some obstacles T(rees) the player cant walk through.
Now my question is... how do we let the computer come up with the best solution to walk from startpoint to endpoint ??
and what about this example:
mapdata:
db 0,0,0,T,0,0,0,9,0,0
db 0,0,0,T,T,T,T,T,T,0
db 0,0,0,0,0,0,0,0,0,0
db 0,0,T,T,T,T,T,T,0,0
db 0,0,0,1,0,0,T,T,T,T
db T,T,T,T,T,T,T,T,T,0
thanx for your help....