Ejemplo n.º 1
0
        /// <summary>
        /// 将这个点的周围都加入到开放合集;
        /// </summary>
        void OpenNeighbors(PathNode parent)
        {
            var neighbors = parent.Position.GetNeighbours();

            foreach (var neighbor in neighbors)
            {
                if (!closePointsSet.Contains(neighbor))
                {
                    PathNode neighborNode;
                    if (IsOutRange(neighbor))
                    {
                        closePointsSet.Add(neighbor);
                    }
                    else if (openPointsSet.TryGetValue(neighbor, out neighborNode))
                    {
                        neighborNode.TryChangeParent(parent);
                    }
                    else if (!Walker.IsWalkable(neighbor))
                    {
                        closePointsSet.Add(neighbor);
                    }
                    else
                    {
                        int cost = Walker.GetCost(parent.Position, neighbor, Destination);
                        neighborNode = new PathNode(parent, neighbor, cost);
                        openPointsSet.Add(neighborNode);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 是否这个点的周围点都无法行走?
        /// </summary>
        bool IsTrapped(T position)
        {
            var neighbors = position.GetNeighbours();

            foreach (var neighbor in neighbors)
            {
                if (Walker.IsWalkable(neighbor))
                {
                    return(false);
                }
            }
            return(true);
        }