protected virtual void ProcessChildNode(NodeRecord parent, NavigationGraphEdge connectionEdge)
        {
            var childNode       = connectionEdge.ToNode;
            var childNodeRecord = new NodeRecord
            {
                node   = childNode,
                parent = parent,
                gValue = parent.gValue + connectionEdge.Cost,
                hValue = this.Heuristic.H(childNode, this.GoalNode)
            };

            childNodeRecord.fValue = F(childNodeRecord);
            NodeRecord openNode   = Open.SearchInOpen(childNodeRecord);
            NodeRecord closedNode = Closed.SearchInClosed(childNodeRecord);

            if (openNode == null && closedNode == null)
            {
                Open.AddToOpen(childNodeRecord);
            }
            else if (openNode != null && openNode.fValue > childNodeRecord.fValue)
            {
                Open.Replace(openNode, childNodeRecord);
            }
            else if (closedNode != null && closedNode.fValue > childNodeRecord.fValue)
            {
                Closed.RemoveFromClosed(closedNode);
                Open.AddToOpen(childNodeRecord);
            }
        }
        protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int connectionIndex)
        {
            //this is where you process a child node
            var childNode = GenerateChildNodeRecord(parentNode, connectionEdge);

            NodeRecord openNode  = Open.SearchInOpen(childNode);
            NodeRecord closeNode = Closed.SearchInClosed(childNode);

            if (openNode == null && closeNode == null)
            {
                this.Open.AddToOpen(childNode);
            }
            else if (openNode != null && childNode.fValue < openNode.fValue)
            {
                Open.Replace(openNode, childNode);
            }
            else if (openNode != null && childNode.fValue == openNode.fValue)
            {
                if (childNode.hValue < openNode.hValue)
                {
                    Open.Replace(openNode, childNode);
                }
            }
            else if (closeNode != null && childNode.fValue < closeNode.fValue)
            {
                Closed.RemoveFromClosed(closeNode);
                Open.AddToOpen(childNode);
            }
        }
        protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            //this is where you process a child node
            var        childNode  = GenerateChildNodeRecord(parentNode, connectionEdge);
            NodeRecord childOpen  = Open.SearchInOpen(childNode);
            NodeRecord childClose = Closed.SearchInClosed(childNode);

            if (childOpen == null && childClose == null)
            {
                Open.AddToOpen(childNode);
                if (this.MaxOpenNodes < Open.CountOpen())
                {
                    this.MaxOpenNodes = Open.CountOpen();
                }
                // childOpen.status = NodeStatus.Open;
            }

            else if (childOpen != null && childOpen.fValue > childNode.fValue)
            {
                Open.Replace(childOpen, childNode);
            }

            else if (childClose != null && childClose.fValue > childNode.fValue)
            {
                Closed.RemoveFromClosed(childClose);
                Open.AddToOpen(childNode);
                //childOpen.status = NodeStatus.Open;
            }
        }
Example #4
0
        protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            //this is where you process a child node
            var childNode = GenerateChildNodeRecord(parentNode, connectionEdge);
            //TODO: implement the rest of the code here
            var nodeOpen  = Open.SearchInOpen(childNode);
            var nodeClose = Closed.SearchInClosed(childNode);

            if (nodeOpen != null)
            {
                if (nodeOpen.fValue >= childNode.fValue)
                {
                    Open.RemoveFromOpen(nodeOpen);
                    Open.AddToOpen(childNode);
                }
                return;
            }
            else if (nodeClose != null)
            {
                if (nodeClose.fValue > childNode.fValue)
                {
                    Closed.RemoveFromClosed(nodeClose);
                    Open.AddToOpen(childNode);
                }
                return;
            }
            Open.AddToOpen(childNode);
        }
        protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            var childNode       = connectionEdge.ToNode;
            var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode);

            if (childNodeRecord == null)
            {
                //this piece of code is used just because of the special start nodes and goal nodes added to the RAIN Navigation graph when a new search is performed.
                //Since these special goals were not in the original navigation graph, they will not be stored in the NodeRecordArray and we will have to add them
                //to a special structure
                //it's ok if you don't understand this, this is a hack and not part of the NodeArrayA* algorithm, just do NOT CHANGE THIS, or your algorithm will not work
                childNodeRecord = new NodeRecord
                {
                    node   = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            childNodeRecord.gValue = bestNode.gValue + (childNode.LocalPosition - bestNode.node.LocalPosition).magnitude;
            childNodeRecord.hValue = this.Heuristic.H(childNode, this.GoalNode);
            childNodeRecord.fValue = F(childNodeRecord);

            NodeRecord nodeInOpen   = Open.SearchInOpen(childNodeRecord);
            NodeRecord nodeInClosed = Closed.SearchInClosed(childNodeRecord);

            if (nodeInOpen == null && nodeInClosed == null)
            {
                Open.AddToOpen(childNodeRecord);
            }
            else if (nodeInOpen != null && childNodeRecord.fValue < nodeInOpen.fValue)
            {
                Open.Replace(nodeInOpen, childNodeRecord);
            }

            else if (nodeInClosed != null && childNodeRecord.fValue < nodeInClosed.fValue)
            {
                Closed.RemoveFromClosed(nodeInClosed);
                Open.AddToOpen(childNodeRecord);
            }
        }
Example #6
0
        protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            var childNodeRecord    = GenerateChildNodeRecord(bestNode, connectionEdge);
            var oldChildNodeOpen   = Open.SearchInOpen(childNodeRecord);
            var oldChildNodeClosed = Closed.SearchInClosed(childNodeRecord);

            if ((oldChildNodeClosed == null) && (oldChildNodeOpen == null))
            {
                Open.AddToOpen(childNodeRecord);
            }
            else if ((oldChildNodeOpen != null) && oldChildNodeOpen.fValue > childNodeRecord.fValue)
            {
                Open.Replace(oldChildNodeOpen, childNodeRecord);
            }
            else if ((oldChildNodeClosed != null) && oldChildNodeClosed.fValue > childNodeRecord.fValue)
            {
                Closed.RemoveFromClosed(oldChildNodeClosed);
                Open.AddToOpen(childNodeRecord);
            }
        }
Example #7
0
        protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            var        childNode    = GenerateChildNodeRecord(parentNode, connectionEdge);
            NodeRecord nodeInOpen   = Open.SearchInOpen(childNode);
            NodeRecord nodeInClosed = Closed.SearchInClosed(childNode);

            if (nodeInOpen == null && nodeInClosed == null)
            {
                Open.AddToOpen(childNode);
            }
            else if (nodeInOpen != null && childNode.fValue < nodeInOpen.fValue)
            {
                Open.Replace(nodeInOpen, childNode);
            }

            else if (nodeInClosed != null && childNode.fValue < nodeInClosed.fValue)
            {
                Closed.RemoveFromClosed(nodeInClosed);
                Open.AddToOpen(childNode);
            }
        }
Example #8
0
        protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            //this is where you process a child node
            var ChildNode       = GenerateChildNodeRecord(bestNode, connectionEdge);
            var ChildNodeOpen   = Open.SearchInOpen(ChildNode);
            var ChildNodeClosed = Closed.SearchInClosed(ChildNode);

            if ((ChildNodeClosed == null) && (ChildNodeOpen == null))
            {
                Open.AddToOpen(ChildNode);
            }
            else if ((ChildNodeOpen != null) && ChildNodeOpen.fValue >= ChildNode.fValue)
            {
                Open.Replace(ChildNodeOpen, ChildNode);
            }
            else if ((ChildNodeClosed != null) && ChildNodeClosed.fValue > ChildNode.fValue)
            {
                Closed.RemoveFromClosed(ChildNodeClosed);
                Open.AddToOpen(ChildNode);
            }
        }
Example #9
0
        protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            //this is where you process a child node
            NodeRecord childNode  = GenerateChildNodeRecord(bestNode, connectionEdge);
            NodeRecord openNode   = Open.SearchInOpen(childNode);
            NodeRecord closedNode = Closed.SearchInClosed(childNode);
            bool       inOpen     = openNode != null ? true : false;
            bool       inClosed   = closedNode != null ? true : false;

            if (!inOpen && !inClosed)
            {
                Open.AddToOpen(childNode);
            }
            else if (inOpen && childNode.fValue < openNode.fValue)
            {
                Open.RemoveFromOpen(openNode);
                Open.AddToOpen(childNode);
            }
            else if (inClosed && childNode.fValue < closedNode.fValue)
            {
                Closed.RemoveFromClosed(closedNode);
                Open.AddToOpen(childNode);
            }
        }
Example #10
0
        //this method should return true if it finished processing, and false if it still needs to continue
        public bool MapFloodDijkstra()
        {
            var processedNodes = 0;

            while (Open.CountOpen() > 0)
            {
                processedNodes++;

                if (processedNodes > NodesPerFlood)
                {
                    return(false);
                }
                LocationRecord currentRecord = Open.GetBestAndRemove();
                Closed.AddToClosed(currentRecord);

                int outConnections = currentRecord.Location.OutEdgeCount;
                for (int i = 0; i < outConnections; i++)
                {
                    var   location  = GenerateChildNodeRecord(currentRecord, currentRecord.Location.EdgeOut(i));
                    float influence = InfluenceFunction.DetermineInfluence(currentRecord.StrongestInfluenceUnit, location.Location.Position);

                    if (InfluenceThreshold.CompareTo(influence) > 0)
                    {
                        continue;
                    }

                    LocationRecord neighborRecord = Closed.SearchInClosed(location);

                    if (neighborRecord != null)
                    {
                        if (neighborRecord.Influence >= influence)
                        {
                            continue;
                        }
                        else
                        {
                            Closed.RemoveFromClosed(neighborRecord);
                        }
                    }
                    else
                    {
                        neighborRecord = Open.SearchInOpen(location);

                        if (neighborRecord != null)
                        {
                            if (neighborRecord.Influence < influence)
                            {
                                neighborRecord.StrongestInfluenceUnit = currentRecord.StrongestInfluenceUnit;
                                neighborRecord.Influence = influence;
                            }
                            continue;
                        }
                        else //we found a new record not in open or closed
                        {
                            neighborRecord          = new LocationRecord();
                            neighborRecord.Location = location.Location;
                        }
                    }

                    neighborRecord.StrongestInfluenceUnit = currentRecord.StrongestInfluenceUnit;
                    neighborRecord.Influence = influence;
                    Open.AddToOpen(neighborRecord);
                }
            }

            this.InProgress = false;
            //this.CleanUp();
            return(true);
        }
Example #11
0
        protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            float f;
            float g;
            float h;

            var childNode       = connectionEdge.ToNode;
            var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode);

            #region do not look into this
            if (childNodeRecord == null)
            {
                //this piece of code is used just because of the special start nodes and goal nodes added to the RAIN Navigation graph when a new search is performed.
                //Since these special goals were not in the original navigation graph, they will not be stored in the NodeRecordArray and we will have to add them
                //to a special structure
                //it's ok if you don't understand this, this is a hack and not part of the NodeArrayA* algorithm, just do NOT CHANGE THIS, or your algorithm will not work
                childNodeRecord = new NodeRecord
                {
                    node   = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }
            #endregion

            h = this.Heuristic.H(childNode, this.GoalNode);
            g = bestNode.gValue + connectionEdge.Cost;
            f = g + h;

            NodeRecord nodeOpen   = this.Open.SearchInOpen(childNodeRecord);
            NodeRecord closedNode = this.Closed.SearchInClosed(childNodeRecord);

            if (nodeOpen != null)
            {
                if (nodeOpen.fValue >= f)
                {
                    Open.RemoveFromOpen(nodeOpen);
                    childNodeRecord.parent = bestNode;
                    childNodeRecord.gValue = g;
                    childNodeRecord.hValue = h;
                    childNodeRecord.fValue = f;
                    Open.AddToOpen(childNodeRecord);
                }
                return;
            }
            else if (closedNode != null)
            {
                if (closedNode.fValue > f)
                {
                    Closed.RemoveFromClosed(closedNode);
                    childNodeRecord.parent = bestNode;
                    childNodeRecord.gValue = g;
                    childNodeRecord.hValue = h;
                    childNodeRecord.fValue = f;
                    Open.AddToOpen(childNodeRecord);
                }
                return;
            }
            childNodeRecord.parent = bestNode;
            childNodeRecord.gValue = g;
            childNodeRecord.hValue = h;
            childNodeRecord.fValue = f;
            Open.AddToOpen(childNodeRecord);
        }