public Dictionary<Vector2, Tile> GetMovementTilesInRadius(Vector2 center, int distance, int controllingPlayerId)
{
var ret = new Dictionary<Vector2, Tile>();
if (distance <= 0) return ret;
var frontier = new List<Vector2>();
var g_score = new Dictionary<Vector2, int>();
g_score[center] = 0; // Cost from start along best known path.
frontier.Add(center);
while (frontier.Count > 0)
{
var current = frontier[0];
var currentTile = mapModel.tiles[current];
frontier.RemoveAt(0);
if (g_score[current] > distance)
{
continue;
}
if (!ret.ContainsKey(current))
{
ret.Add(current, currentTile);
}
var neighbors = GetMovableNeighbors(currentTile, controllingPlayerId);
foreach (var neighbor in neighbors)
{
//add the neighbor to explore if it's not already being returned
//or in the queue or too far away
if (
!ret.ContainsKey(neighbor.Key)
&& !frontier.Contains(neighbor.Key)
&& TileDistance(neighbor.Key, center) <= distance
)
{
g_score[neighbor.Key] = g_score[current] + 1;
frontier.Add(neighbor.Key);
}
}
}
return ret;
}