Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best method for movement possibilties calculation.
#1
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 Big Grin

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
Reply
#2
There was an article on A* pathing in the last issue of QBExpress. You might want to check it out. Basically you need to calculate the cost for each tile to the movement diatance. There are other ways to do this though.

In my rogue-like I iterate through the map, calc the distance from the player character to a tile to see if it is within his range. I just skip over impassable tiles since each tile cost the same.

Another way to do this is to use a flood-fill type algo, starting from the pc tile. For each tile you would calculate the movement cost and distance, skipping over impassable tiles. Here is my flood-fill routine that I am using to create a sound map for my rogue-like:

Code:
Sub CalcSoundMap(x As Integer, y As Integer, soundval As Integer)
    Dim csound As Integer
    Dim sdist As Integer
    
    If x < 0 Or x > dunw - 1 Then Exit Sub
    If y < 0 Or y > dunh - 1 Then Exit Sub
    If soundval <= 0 Then Exit Sub
    If BlockingTile(x, y) Then Exit Sub
    If levels.soundmap(x, y) > 0 Then Exit Sub
    sdist = CalcDist(player.pcoord.x, x, player.pcoord.y, y)
    csound = soundval - (sdist * sdist)
    If csound <= 0 Then Exit Sub
    levels.soundmap(x, y) = csound
    CalcSoundMap x+1, y, csound
    CalcSoundMap x, y+1, csound
    CalcSoundMap x-1, y, csound
    CalcSoundMap x, y-1, csound
    CalcSoundMap x+1, y+1, csound
    CalcSoundMap x-1, y+1, csound
    CalcSoundMap x-1, y-1, csound
    CalcSoundMap x+1, y-1,  csound
End Sub

Notice this a a recursive routine, so you must add an exit condition. The BlockingTile function checks to see if a tile is impassable and skips it if it is. This is an eight way flood-fill. If your units cannot go diagonally, then just use a four way flood-fill.

I am sure there are other ways to do this as well.
Reply
#3
Ray casting? I don't know. I like the challenge though :p. I oughta figure this out and write an article about it.
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)