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


C# Path.AddNode方法代码示例

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


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

示例1: getPath

        private static Path getPath(Dictionary<Node, Node> moves, Node end)
        {
            Path path = new Path();

            path.AddNode(end);
            while (moves.ContainsKey(end))
            {
                end = moves[end];
                path.AddNode(end);
            }

            path.Reverse();

            return path;
        }
开发者ID:cedwards145,项目名称:ld33,代码行数:15,代码来源:AStarPathfinder.cs

示例2: FindPath

    public Path FindPath( Vector3 startPos, Vector3 endPos )
    {
        // Check if endPos is valid
        if ( gridGenerator.Grid[Mathf.FloorToInt( endPos.x ), Mathf.FloorToInt( endPos.z )] ) {
            // End pos is not available; return a path with only startPos
            Path p = new Path();
            p.AddNode( startPos );
            return p;
        }

        // Find a path
        Dictionary<Vector3, Vector3> cameFrom = new Dictionary<Vector3, Vector3>();

        List<Vector3> closedSet = new List<Vector3>();
        List<Vector3> openSet = new List<Vector3>();
        openSet.Add( startPos );

        Dictionary<Vector3, float> gScores = new Dictionary<Vector3, float>(); // Cost from start along best-known path
        gScores[startPos] = 0;

        Dictionary<Vector3, float> fScores = new Dictionary<Vector3, float>(); // Estimated total cost
        fScores[startPos] = gScores[startPos] + GuessDistanceHeuristic( startPos, endPos );

        while ( openSet.Count > 0 ) {
            Vector3 currentNode = GetLowestFScore( openSet, fScores );
            if ( CalcDist( currentNode, endPos ) < 1.0f ) {
                return ReconstructPath( cameFrom, currentNode );
            }

            openSet.Remove( currentNode );
            closedSet.Add( currentNode );

            foreach ( Vector3 neighbor in GetNeigbors( currentNode ) ) {
                float tempGScore = gScores[currentNode] + Vector3.Distance( currentNode, neighbor );
                if ( closedSet.Contains( neighbor ) ) {
                    if ( tempGScore >= gScores[neighbor] ) {
                        continue;
                    }
                }

                if ( !openSet.Contains( neighbor ) || tempGScore < gScores[neighbor] ) {
                    cameFrom[neighbor] = currentNode;
                    gScores[neighbor] = tempGScore;
                    fScores[neighbor] = gScores[neighbor] + GuessDistanceHeuristic( neighbor, endPos );
                    if ( !openSet.Contains( neighbor ) ) {
                        openSet.Add( neighbor );
                    }
                }
            }
        }

        // If we reached here, we failed to find a path. Return a straight line.
        return PlaceholderPath( startPos, endPos );
    }
开发者ID:ZachHoefler,项目名称:RTSControls,代码行数:54,代码来源:PathGenerator.cs

示例3: ReconstructPath

 private Path ReconstructPath( Dictionary<Vector3, Vector3> cameFrom, Vector3 currentNode )
 {
     if ( cameFrom.ContainsKey( currentNode ) ) {
         Path p = ReconstructPath( cameFrom, cameFrom[currentNode] );
         p.AddNode( currentNode );
         return p;
     } else {
         Path p = new Path();
         p.AddNode( currentNode );
         return p;
     }
 }
开发者ID:ZachHoefler,项目名称:RTSControls,代码行数:12,代码来源:PathGenerator.cs


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