本文整理汇总了C#中HexPosition.dist方法的典型用法代码示例。如果您正苦于以下问题:C# HexPosition.dist方法的具体用法?C# HexPosition.dist怎么用?C# HexPosition.dist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HexPosition
的用法示例。
在下文中一共展示了HexPosition.dist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: search
//Start from start, move to within distance of goal within max steps.
public static HexPosition[] search(HexPosition start, HexPosition goal, int max, int distance = 0)
{
max += distance; //Now it's the maximum distance to the goal, instead of just the maximum number of steps.
//HashSet<HexPosition> closedSet = new HashSet<HexPosition>(); // The set of nodes already evaluated.
//HashSet<HexPosition> openSet = new HashSet<HexPosition>(start); // The set of tentative nodes to be evaluated, initially containing the start node
Dictionary<HexPosition, HexPosition> cameFrom = new Dictionary<HexPosition, HexPosition>(); // The map of navigated nodes.
Dictionary<HexPosition, int> gScore = new Dictionary<HexPosition, int>(); // Cost from start along best known path. Domain is the open and closed sets.
Dictionary<HexPosition, int> fScore = new Dictionary<HexPosition, int>(); // Estimated total cost from start to goal through y. Domain is the open set.
gScore.Add(start, 0);
fScore.Add(start, start.dist(goal));
while (fScore.Count > 0)
{
HexPosition current = getMin(fScore);
if (current.dist(goal) <= distance)
{
int length = 0;
gScore.TryGetValue(current, out length);
return reconstructPath(cameFrom, current, length + 1);
}
fScore.Remove(current);
foreach (HexPosition neighbor in current.Neighbors)
{
if (neighbor.containsKey("Obstacle") || neighbor.containsKey("Unit"))
{
continue; //Make this more general.
}
if (gScore.ContainsKey(neighbor) && !fScore.ContainsKey(neighbor))
{
continue;
}
int tentativeGScore = 0;
gScore.TryGetValue(current, out tentativeGScore);
++tentativeGScore;
if (tentativeGScore > max)
{
continue;
}
int neighborGScore = 0;
gScore.TryGetValue(current, out neighborGScore);
if (!fScore.ContainsKey(neighbor) || tentativeGScore < neighborGScore)
{
int newFScore = tentativeGScore + neighbor.dist(goal);
if (newFScore > max)
{
continue;
}
cameFrom.Add(neighbor, current);
gScore.Add(neighbor, tentativeGScore);
fScore.Add(neighbor, newFScore);
}
}
}
return new HexPosition[0] { };
}
示例2: isAttackable
//TODO: Move to Unit.cs
private bool isAttackable(Unit attacker, Unit attacked, HexPosition coordinates)
{
return attacked.PLAYER != player && coordinates.dist(attacked.Coordinates) <= attacker.RANGE;
}