Range Sight Algorithm
An algorithm to determine how far a unit can move in a given turn.
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(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.
Related Tutorials
Balancing Game Development and Creative Direction in Indie Production
A practical look at how indie developers can balance creative direction with hands-on game development. This article co…
My Unreal Engine Development Process: From Core Idea to Playable Build
A practical overview of my Unreal Engine development process, covering how I move from a core game idea to a playable b…
Introducing LaneGraph: The Ultimate Road Network Solution for Unity
Discover the power of LaneGraph, a lightweight and flexible lane-based navigation system for Unity. LaneGraph makes it…
Retargeting Mixamo Characters with Root Motion In Unreal Engine 5.4.
I have always found Retargeting Mixamo Characters To have Root Motion is a serious lengthy Tast, Recently I stumbled up…
How To Make A SIMPLE Main Menu In Unity
In this tutorial for unity, i go over how to make a simple main menu for unity, it's an unlisted video because i do not…
Guide to Gameplay Balance
A perspective on competitive gameplay balance, from a background of "shooter" sandbox design.
Discussion
More from Amit Patel
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion