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


C# Heap.size方法代码示例

本文整理汇总了C#中Heap.size方法的典型用法代码示例。如果您正苦于以下问题:C# Heap.size方法的具体用法?C# Heap.size怎么用?C# Heap.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Heap的用法示例。


在下文中一共展示了Heap.size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindPath

    public List<Portal> FindPath()
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        bool success = false;
        CreateStartNode(startPos);
        CreateEndNode(targetPos);
        if (startPortal == null || endPortal == null)
            return null;

        Heap<Portal> frontier = new Heap<Portal>(portals.Count+2);
        HashSet<Portal> visited = new HashSet<Portal>();
        frontier.Add(startPortal);

        while(frontier.size() > 0){
            Portal current = frontier.RemoveFirst();
            visited.Add(current);

            if (current == endPortal){
                sw.Stop();
                success = true;
                print("Path found in: "+ sw.ElapsedMilliseconds + " ms");
                break;
            }

            foreach(KeyValuePair<Portal, int> nb in current.GetNeighbours()){
                if (visited.Contains(nb.Key)){
                    continue;
                }

                int newDistance = current.gCost + nb.Value;
                if (newDistance < nb.Key.gCost || !frontier.Contains(nb.Key)){
                    nb.Key.gCost = newDistance;
                    nb.Key.hCost = CalcDistance(nb.Key);
                    nb.Key.SetParent(current);

                    if (!frontier.Contains(nb.Key)){
                        frontier.Add(nb.Key);
                    }
                }
            }
        }
        if (success){
            return RetracePath();
        }
        else return null;
    }
开发者ID:AndreaBrg,项目名称:LazierTurtle,代码行数:47,代码来源:Graph.cs

示例2: FindConnections

    /// <summary>
    /// Finds the connections.
    /// </summary>
    /// <param name="start">Start.</param>
    public void FindConnections(Node start)
    {
        Tile startTile = TileFromPosition (start.center);
        Dictionary<Tile, Node> targets = new Dictionary<Tile, Node> ();
        foreach (KeyValuePair<Vector3, Node> kv in nodes) {
            if (kv.Value != start)
                targets.Add (TileFromPosition (kv.Key), kv.Value);
        }

        if (startTile.cost == 255)
            return;

        Heap<Tile> frontier = new Heap<Tile> (sizeX * sizeY);
        HashSet<Tile> visited = new HashSet<Tile> ();
        frontier.Add (startTile);

        while (frontier.size () > 0) {
            Tile current = frontier.RemoveFirst ();
            visited.Add (current);

            Node intranode = null;
            targets.TryGetValue (current, out intranode);
            if (intranode != null && !intranode.ConnectedTo (start)) {
                Node.Connect (start, intranode, current.distance);
            }

            foreach (Tile neighbour in GetNeighbours(current)) {
                if (neighbour == null || neighbour.cost == 255 || visited.Contains (neighbour)) {
                    continue;
                }
                neighbour.distance = current.distance + 1;
                if (!frontier.Contains (neighbour))
                    frontier.Add (neighbour);
            }
        }
    }
开发者ID:AndreaBrg,项目名称:LazierTurtle,代码行数:40,代码来源:Sector.cs

示例3: FindConnections

    void FindConnections(Portal portal, Cluster cluster, bool oriented)
    {
        Heap<Tile> queue = new Heap<Tile> (Cluster.size * Cluster.size);
        HashSet<Tile> visited = new HashSet<Tile> ();
        int pcount = cluster.GetPortals ().Count - 1;

        foreach (Tile t in portal.GetPortalTiles()) {
            t.distance = 0;
            queue.Add (t);
        }

        while (queue.size () > 0 && pcount > 0) {
            Tile current = queue.RemoveFirst ();
            visited.Add (current);

            Portal newPortal = current.GetPortal ();
            if (newPortal != null && newPortal != portal) {
                if (!portal.ConnectedTo (newPortal) && current.distance>0) {
                    if (!oriented) {
                        Portal.Connect (portal, newPortal, current.distance);
                    } else {
                        portal.AddNeighbour (newPortal, current.distance);
                    }
                    pcount--;
                }
            }

            foreach (Tile nb in cluster.GetNeighbours(current)) {
                if (nb == null || nb.cost == 255 || visited.Contains (nb))
                    continue;

                nb.distance = current.distance + 1;
                if (!queue.Contains (nb))
                    queue.Add (nb);
            }
        }
    }
开发者ID:AndreaBrg,项目名称:LazierTurtle,代码行数:37,代码来源:Graph.cs

示例4: FloodFill

    /// <summary>
    /// Generate the distance values and the relative flow vector.
    /// </summary>
    /// <param name="start">Start.</param>
    public void FloodFill(Vector3 start)
    {
        for (int x = 0; x < sizeX; x++) {
            for (int y = 0; y < sizeY; y++) {
                grid [x, y].distance = int.MaxValue;
            }
        }

        Tile startTile = TileFromPosition (start);
        if (startTile.cost == 255)
            return;

        startTile.distance = 0;
        Heap<Tile> queue = new Heap<Tile> (sizeX * sizeY);
        HashSet<Tile> visited = new HashSet<Tile> ();

        queue.Add (startTile);

        while (queue.size () > 0) {
            Tile t = queue.RemoveFirst ();
            visited.Add (t);

            Tile[] neighbours = GetNeighbours (t);
            foreach (Tile nb in neighbours) {
                if (nb == null || nb.cost == 255 || visited.Contains (nb))
                    continue;

                nb.distance = t.distance + 1;
                if (!queue.Contains (nb))
                    queue.Add (nb);
            }

            for (int i = 0; i < 4; i++) {
                if (neighbours [i] == null || neighbours [i].cost == 255)
                    neighbours [i] = t;
            }
            float flowx = neighbours [2].distance - neighbours [3].distance;
            float flowy = neighbours [0].distance - neighbours [1].distance;
            t.flow = new Vector2 (flowx, flowy).normalized;
        }
    }
开发者ID:AndreaBrg,项目名称:LazierTurtle,代码行数:45,代码来源:Sector.cs


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