本文整理汇总了C#中Heap.modify方法的典型用法代码示例。如果您正苦于以下问题:C# Heap.modify方法的具体用法?C# Heap.modify怎么用?C# Heap.modify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap.modify方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: calculateRoute
private static Stack<Cell> calculateRoute(Cell from, Cell to, Entity entity, int distance)
{
Cell[] cells = from.Map.GetComponentsInChildren<Cell>();
Dictionary<Cell,int> cellToPos = new Dictionary<Cell, int>();
for(int i = 0; i<cells.Length; i++)
cellToPos[cells[i]] = i;
Heap<float> abierta = new Heap<float>(cells.Length);
bool[] cerrada = new bool[cells.Length];
for (int i = 0; i < cells.Length; i++)
cerrada[i] = false;
float[] f = new float[cells.Length];
float[] g = new float[cells.Length];
Cell[] anterior = new Cell[cells.Length];
for (int i = 0; i < cells.Length; i++)
anterior[i] = null;
int posInicial = cellToPos[from];
g[posInicial] = 0;
f[posInicial] = estimaMeta(from, to);
anterior[posInicial] = null;
abierta.push(posInicial + 1, f[posInicial]);
List<Cell> ends = GetSurroundCellsAtRadius(to, distance);
while (!abierta.isEmpty()){
int candidata = abierta.top().elem - 1;
abierta.pop();
Cell celdaCandidata = cells[candidata];
if (ends.Contains(celdaCandidata)){
Stack<Cell> ruta = new Stack<Cell>();
reconstruyeCamino(ruta, candidata, anterior, cells, cellToPos);
return ruta;
}
Cell[] accesibles = getCeldasAccesibles(celdaCandidata, entity);
cerrada[candidata] = true;
foreach (Cell accesible in accesibles)
{
int posAccesible = cellToPos[accesible];
float posibleG = g[candidata] + estimaAvance(celdaCandidata, accesible);
float posibleF = posibleG + estimaMeta(accesible, to);
if (cerrada[posAccesible] && posibleF >= f[posAccesible])
continue;
if (!abierta.contains(posAccesible + 1) || posibleF < f[posAccesible])
{
anterior[posAccesible] = celdaCandidata;
g[posAccesible] = posibleG;
f[posAccesible] = posibleF;
abierta.modify(posAccesible + 1, f[posAccesible]); // Modifica inserta si no esta dentro
}
}
}
return null;
}