Grind movement possibilities

BlitzMax Forums/BlitzMax Programming/Grind movement possibilities

Drakim(Posted 2008) [#1]
To put it short, I have a grind, and need to find out which squares you can reach from a point if you have limited steps. Some squares in the grind are "solid" so you can't use them for reaching other squares.

Final Fantasy Tactics (among other games) use this system.



So, I have no idea how this is done. Anything I can think up would require hundreds of loops, which obvious isn't very usable. ^^;;

So, any suggestions?


jsp(Posted 2008) [#2]
A* Pathfinder?
Does this help:
http://www.blitzbasic.com/codearcs/codearcs.php?code=2162


Warpy(Posted 2008) [#3]
a little recursive function should do it:

pseudocode:

function checkreachable(x,y)
   if solid(x,y) or checked[x,y] then return
   checked[x,y] = 1
   checkreachable(x-1,y)
   checkreachable(x+1,y)
   checkreachable(x,y-1)
   checkreachable(x,y+1)
end function



Drakim(Posted 2008) [#4]
jsp: It wasn't the pathing itself I was looking for, but a way to simply establish if a square is reachable.


Warpy:
Thank you! Although your code lacks a "max movement" limit, I see what it does. ^^


johnnyfreak(Posted 2008) [#5]
for recursion depth you can pass another parameter to the function
function checkreachable(x,y, depth)
   if depth=0 or solid(x,y) or checked[x,y] then return
   checked[x,y] = 1
   checkreachable(x-1,y,depth-1)
   checkreachable(x+1,y,depth-1)
   checkreachable(x,y-1,depth-1)
   checkreachable(x,y+1,depth-1)
end function



Drakim(Posted 2008) [#6]
exactly. I've already added my own version of the function to my game. it works perfectly. ^^


Gabriel(Posted 2008) [#7]
Look up the Breadth-First search. It's more or less what has been posted, but might give you some extra ideas.


Drakim(Posted 2008) [#8]
Gabriel, thank you, it was indeed an interesting and knowledge blessing read. I think I will have opportunities to use it in more than just path finding.


slenkar(Posted 2008) [#9]
just a tip:
its grid not grind
that may help if you look on google for 'grid' related stuff


Drakim(Posted 2008) [#10]
hey, you are right. but "grind" returned results too. Seems it's a common typo. ^^


Damien Sturdy(Posted 2008) [#11]
Hm! Look up, "Karma Sutra." Grinding is not the main course.

Oh sh*t, this is the wrong forum!