当前位置: 首页>>代码示例>>C#>>正文


C# Heap.push方法代码示例

本文整理汇总了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;
    }
开发者ID:nvidiosin,项目名称:IsoAbbey,代码行数:64,代码来源:RoutePlanifier.cs

示例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;
 }
开发者ID:nvidiosin,项目名称:isoAbbeyTFG,代码行数:32,代码来源:Map.cs


注:本文中的Heap.push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。