本文整理汇总了C#中Heap.push方法的典型用法代码示例。如果您正苦于以下问题:C# Heap.push方法的具体用法?C# Heap.push怎么用?C# Heap.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap.push方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: fillControllerEvent
public void fillControllerEvent(ControllerEventArgs args)
{
bool encontrado = false;
if(args.isLeftDown){
RaycastHit[] hits = Physics.RaycastAll(Camera.main.ScreenPointToRay(args.mousePos));
if(hits.Length>0){
Heap<float> pqHits = new Heap<float>(hits.Length);
for(int i = 0; i<hits.Length; i++){
if(hits[i].collider.transform.IsChildOf(this.transform))
pqHits.push(i+1, hits[i].distance);
}
while(!encontrado && !pqHits.isEmpty()){
RaycastHit hit = hits[pqHits.top().elem-1];
pqHits.pop();
Cell c = hit.collider.GetComponent<Cell>();
if(c!=null){
args.cell = c;
Entity[] entities = c.getEntities();
if(entities.Length==1)
fillEntity(entities[0], args);
encontrado = true;
}else{
Entity e = hit.collider.GetComponent<Entity>();
if(e!=null)
fillEntity(e,args);
encontrado=true;
}
}
}
}
args.send = args.UP || args.DOWN || args.LEFT || args.RIGHT || encontrado;
}