09-16-2005, 07:13 PM
I'm coding this tilebased turn to turn wargame. As in most wargames each unit has an amount of movement points to move into connected tiles.
Now i'm investigating which method is the best for implenting this system where the game shows you which tiles are possible for you to move on. Now this ain't so hard to figure out,
unitX = 10
unitY = 14
movementpoints = 5
just add or substract your unit cordinates with the movementpoints
but when there obstables on some tiles, where the unit can't go but maybe around, it's gettin hard. I was looking on the internet on some pathfinding articles and saw the A* methods but i wondered if that's the right method for what i want. Is there another way out?
I hope my problem is clear enough
Edit:
Now i found this pseudecode on amit's programming site, but i don't really understand it. Could someone translate his words in more Basic-compatible (pseudo)code?
Let Costs be an array (as big as your map) of integers, init. value = -1
Function Find(UnitLocation)
Let Open be a priority queue of locations /* sorted by Costs[x] */
Let Closed be a set of locations
Put Location in Open
While Open isn't empty:
Remove a location X from Open
Add X to Closed
If Costs[X] is less than the Movement Limit:
For each Y that is a neighbor of X:
NewCost = Costs[X] + MovementCost(from X to Y)
If Costs[Y] is -1 or NewCost is less than Costs[Y]:
Set Costs[Y] to NewCost
Add Y to Open if it's not already in Open
Let Results be a list of locations
For each X in Closed:
If Costs[X] is less than the Movement Limit:
Add X to Results
Set Costs[X] to -1
http://www-cs-students.stanford.edu/~ami...hting.html
Now i'm investigating which method is the best for implenting this system where the game shows you which tiles are possible for you to move on. Now this ain't so hard to figure out,
unitX = 10
unitY = 14
movementpoints = 5
just add or substract your unit cordinates with the movementpoints
but when there obstables on some tiles, where the unit can't go but maybe around, it's gettin hard. I was looking on the internet on some pathfinding articles and saw the A* methods but i wondered if that's the right method for what i want. Is there another way out?
I hope my problem is clear enough
Edit:
Now i found this pseudecode on amit's programming site, but i don't really understand it. Could someone translate his words in more Basic-compatible (pseudo)code?
Let Costs be an array (as big as your map) of integers, init. value = -1
Function Find(UnitLocation)
Let Open be a priority queue of locations /* sorted by Costs[x] */
Let Closed be a set of locations
Put Location in Open
While Open isn't empty:
Remove a location X from Open
Add X to Closed
If Costs[X] is less than the Movement Limit:
For each Y that is a neighbor of X:
NewCost = Costs[X] + MovementCost(from X to Y)
If Costs[Y] is -1 or NewCost is less than Costs[Y]:
Set Costs[Y] to NewCost
Add Y to Open if it's not already in Open
Let Results be a list of locations
For each X in Closed:
If Costs[X] is less than the Movement Limit:
Add X to Results
Set Costs[X] to -1
http://www-cs-students.stanford.edu/~ami...hting.html