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


C# PathNode.toPath方法代码示例

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


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

示例1: findPath

    public Vec2int[] findPath(int startX, int startY, int goalX, int goalY, int restrictCost, bool ignorecollision)
    {
        if((!ignorecollision && (!tiles[startX, startY].traversable || !tiles[goalX, goalY].traversable)) || (startX == goalX && startY == goalY)) return null;
        List<PathNode> reachable = new List<PathNode>();
        List<PathNode> visited = new List<PathNode>();
        reachable.Add(new PathNode(startX, startY));
        while(reachable.Count != 0){
            PathNode cheapest = new PathNode();
            float fcost = -1;
            foreach(PathNode node in reachable){
                if(fcost == -1 || node.f <= fcost){
                    fcost = node.f;
                    cheapest = node;
                }
            }
            if(cheapest.g >= restrictCost){
                return null;
            }
            visited.Add(cheapest);
            reachable.Remove(cheapest);

            foreach(Hexagon hex in tiles[cheapest.x, cheapest.y].getAdjacent()){
                bool gotVisited = false;
                foreach(PathNode vNode in visited){
                    if(hex.gridPos.x == vNode.x && hex.gridPos.y == vNode.y){
                        gotVisited = true;
                        break;
                    }
                }

                if((hex.traversable || ignorecollision) && !gotVisited){
                    bool isReachable= false;
                    foreach(PathNode rNode in reachable){
                        if(hex.gridPos.x == rNode.x && hex.gridPos.y == rNode.y){
                            isReachable = true;
                            rNode.tryAlternative(cheapest);
                            break;
                        }
                    }

                    if(!isReachable){
                        PathNode nNode = new PathNode(hex.gridPos.x, hex.gridPos.y, cheapest, goalX, goalY);
                        if(hex.gridPos.x == goalX && hex.gridPos.y == goalY) return nNode.toPath();
                        reachable.Add(nNode);
                    }
                }
            }
        }
        return null;
    }
开发者ID:vikpek,项目名称:BeforeLegendsBeta,代码行数:50,代码来源:WorldMapData.cs


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