|
by Amit Patel Someone asked me about an algorithm that, given a location of a unit, would tell you what locations can be reached in the next turn. I'm assuming you have a MovementCost function that tells you how hard it is to walk from one space to another. You can use Dijkstra's algorithm to find this area. Let Costs be an array (as big as your map) of integers, init. value = -1
(It's important to keep Costs outside the Find function; otherwise the initialization time for that big array would slow down the whole algorithm. The algorithm restores Costs to -1 at the end so that you can use it the next time you want to Find.) This algorithm should be pretty fast. In practice the number of things that go into Open should be the area (which are spaces you can reach) + the perimeter (which are spaces just out of reach), which is not too high as long as the unit's movement is pretty limited. Discuss this article in the forums
See Also: © 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
|