本文整理汇总了C#中Heap.pop方法的典型用法代码示例。如果您正苦于以下问题:C# Heap.pop方法的具体用法?C# Heap.pop怎么用?C# Heap.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap.pop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPath
void FindPath(Vector3 startPos, Vector3 targetPos) { // performs A* search on the grid to find a path
startPos = new Vector3(startPos.x + 8.0f, 0, startPos.z - 2.0f); // offsets
targetPos = new Vector3(targetPos.x + 8.0f, 0, targetPos.z - 2.0f); // offsets
Node startNode = grid.GetNodeFromWorldPoint(startPos);
Node targetNode = grid.GetNodeFromWorldPoint(targetPos);
if (targetNode.walkable == false) return; // don't try to path find if we're on an unwalkable area
Heap<Node> openSet = new Heap<Node>(grid.MaxSize);
HashSet<Node> closedSet = new HashSet<Node>();
openSet.Add(startNode);
while(openSet.Count > 0) { // we still have nodes
Node currentNode = openSet.pop();
closedSet.Add(currentNode);
if(currentNode == targetNode) { // we've found exit
RetracePath(startNode, targetNode);
path = backTrackPath(startNode, targetNode);
return;
}
foreach(Node n in grid.GetNeighbours(currentNode)) {
if (!n.walkable || closedSet.Contains(n)) continue;
int newMovementCostToNeighbour = currentNode.gCost + GetDistance(currentNode, n);
if(newMovementCostToNeighbour < n.gCost || !openSet.contains(n)) {
n.gCost = newMovementCostToNeighbour;
n.hCost = GetDistance(n, targetNode);
n.parent = currentNode;
if (!openSet.contains(n)) openSet.Add(n); // add our neighbour into open set
else openSet.UpdateItem(n);
}
}
}
}
示例2: 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;
}
示例3: 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;
}