Grind movement possibilities
BlitzMax Forums/BlitzMax Programming/Grind movement possibilities
| ||
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? |
| ||
A* Pathfinder? Does this help: http://www.blitzbasic.com/codearcs/codearcs.php?code=2162 |
| ||
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 |
| ||
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. ^^ |
| ||
for recursion depth you can pass another parameter to the functionfunction 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 |
| ||
exactly. I've already added my own version of the function to my game. it works perfectly. ^^ |
| ||
Look up the Breadth-First search. It's more or less what has been posted, but might give you some extra ideas. |
| ||
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. |
| ||
just a tip: its grid not grind that may help if you look on google for 'grid' related stuff |
| ||
hey, you are right. but "grind" returned results too. Seems it's a common typo. ^^ |
| ||
Hm! Look up, "Karma Sutra." Grinding is not the main course. Oh sh*t, this is the wrong forum! |