Exemple #1
0
    private static void DealNeighbourPathNode(AStarPathNode currentPathNode, AStarPathNode neighbourPathNode, AStarPathNode endPathNode, List <AStarPathNode> openList, List <AStarPathNode> closeList, Dictionary <int, AStarPathNode> openDictionary, Dictionary <int, AStarPathNode> closeDictionary)
    {
        if (neighbourPathNode.IsValidNode() &&
            !IsInList(neighbourPathNode, closeDictionary))
        {
            if (!IsInList(neighbourPathNode, openDictionary))
            {
                neighbourPathNode.ParentPathNode = currentPathNode;
                neighbourPathNode.ValueG         = neighbourPathNode.CalculateValueG(currentPathNode);
                neighbourPathNode.ValueH         = neighbourPathNode.CalculateValueH(endPathNode);
                s_OpenList.Add(neighbourPathNode);
                s_OpenDictionary.Add(neighbourPathNode.Column + (neighbourPathNode.Row << 16), neighbourPathNode);
            }
            else
            {
                neighbourPathNode = openDictionary[neighbourPathNode.Column + (neighbourPathNode.Row << 16)];

                int valueG = neighbourPathNode.CalculateValueG(currentPathNode);
                if (valueG < neighbourPathNode.ValueG)
                {
                    neighbourPathNode.ParentPathNode = currentPathNode;
                    neighbourPathNode.ValueG         = valueG;
                    neighbourPathNode.ValueH         = neighbourPathNode.CalculateValueH(endPathNode);
                }
            }
        }
    }
    private static void DealNeighbourPathNode(AStarPathNode currentPathNode, AStarPathNode neighbourPathNode, AStarPathNode endPathNode, SortedDictionary <int, List <AStarPathNode> > openList, List <AStarPathNode> closeList, Dictionary <int, AStarPathNode> openDictionary, Dictionary <int, AStarPathNode> closeDictionary)
    {
        if (neighbourPathNode.IsValidNode() &&
            !IsInList(neighbourPathNode, closeDictionary))
        {
            if (!IsInList(neighbourPathNode, openDictionary))
            {
                neighbourPathNode.ParentPathNode = currentPathNode;
                neighbourPathNode.ValueG         = neighbourPathNode.CalculateValueG(currentPathNode);
                neighbourPathNode.ValueH         = neighbourPathNode.CalculateValueH(endPathNode);
                if (openList.ContainsKey(neighbourPathNode.ValueF))
                {
                    openList[neighbourPathNode.ValueF].Add(neighbourPathNode);
                }
                else
                {
                    openList.Add(neighbourPathNode.ValueF, new List <AStarPathNode>()
                    {
                        neighbourPathNode
                    });
                }
                openDictionary.Add(neighbourPathNode.Column + (neighbourPathNode.Row << 16), neighbourPathNode);
            }
            else
            {
                neighbourPathNode = openDictionary[neighbourPathNode.Column + (neighbourPathNode.Row << 16)];

                openList[neighbourPathNode.ValueF].Remove(neighbourPathNode);
                if (openList[neighbourPathNode.ValueF].Count == 0)
                {
                    openList.Remove(neighbourPathNode.ValueF);
                }

                int valueG = neighbourPathNode.CalculateValueG(currentPathNode);
                if (valueG < neighbourPathNode.ValueG)
                {
                    neighbourPathNode.ParentPathNode = currentPathNode;
                    neighbourPathNode.ValueG         = valueG;
                    neighbourPathNode.ValueH         = neighbourPathNode.CalculateValueH(endPathNode);
                }

                if (openList.ContainsKey(neighbourPathNode.ValueF))
                {
                    openList[neighbourPathNode.ValueF].Add(neighbourPathNode);
                }
                else
                {
                    openList.Add(neighbourPathNode.ValueF, new List <AStarPathNode>()
                    {
                        neighbourPathNode
                    });
                }
            }
        }
    }