protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
 {
     if (CheckNode(bestNode, connectionEdge))
     {
         base.ProcessChildNode(bestNode, connectionEdge);
     }
 }
        //don't forget to add the override keyword here if you define a ProcessChildNode method in the base class
        protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            float f;
            float g;
            float h;
            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 you algorithm wont work
                childNodeRecord = new NodeRecord
                {
                    node = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

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

            var oldChildNodeOpen = Open.SearchInOpen(childNodeRecord);
            var oldChildNodeClosed = Closed.SearchInClosed(childNodeRecord);

            if ((oldChildNodeClosed == null) && (oldChildNodeOpen == null))
            {

                childNodeRecord.parent = bestNode;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;

                Open.AddToOpen(childNodeRecord);
            }
            else if ((oldChildNodeOpen != null) && f < childNodeRecord.fValue)
            {
                childNodeRecord.parent = bestNode;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;

                Open.Replace(oldChildNodeOpen, childNodeRecord);

            }
            else if ((oldChildNodeClosed != null) && f < childNodeRecord.fValue)
            {
                childNodeRecord.parent = bestNode;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;

                Open.AddToOpen(childNodeRecord);
            }
        }
        //don't forget to add the override keyword here if you define a ProcessChildNode method in the base class
        protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            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 you algorithm wont work
                childNodeRecord = new NodeRecord
                {
                    node = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            float securityValue = 0;
            this.character.SecurityInfluence.TryGetValue(childNode.Position, out securityValue);

            if(securityValue < 0)
            {

                this.NodeRecordArray.AddToClosed(childNodeRecord);
                return;
            }

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

            // if child state is not in open or in closed then insert in open
            if (childNodeRecord.status == NodeStatus.Unvisited)
            {
                UpdateNodeRecord(childNodeRecord, bestNode, g, h);
                this.NodeRecordArray.AddToOpen(childNodeRecord);
            } else
            {
                // if child state is in open with higher F-value replace old one
                if (childNodeRecord.status == NodeStatus.Open && childNodeRecord.fValue > f)
                {
                    UpdateNodeRecord(childNodeRecord, bestNode, g, h);
                    this.NodeRecordArray.Replace(childNodeRecord, childNodeRecord);
                } else
                {
                    // if child state is in close with higher F-value then delete old and add new to open
                    if (childNodeRecord.status == NodeStatus.Closed && childNodeRecord.fValue > f)
                    {
                        UpdateNodeRecord(childNodeRecord, bestNode, g, h);
                        NodeRecordArray.RemoveFromClosed(childNodeRecord);
                        NodeRecordArray.AddToOpen(childNodeRecord);
                    }
                }
            }
        }
        protected new void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            float f;
            float g;
            float h;

            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
                childNodeRecord = new NodeRecord
                {
                    node = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            // implement the rest of your code here

            if (childNodeRecord.status == NodeStatus.Closed) return;

            float influenceCost = CalculateInfluenceCost(bestNode.node, childNode);
            if (influenceCost < 0.0f)
                return;

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

            if (childNodeRecord.status == NodeStatus.Open)
            {
                if (f <= childNodeRecord.fValue)
                {
                    childNodeRecord.gValue = g;
                    childNodeRecord.hValue = h;
                    childNodeRecord.fValue = f;
                    childNodeRecord.parent = bestNode;
                    this.NodeRecordArray.Replace(childNodeRecord,childNodeRecord);
                }
            }
            else
            {
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;
                childNodeRecord.status = NodeStatus.Open;
                childNodeRecord.parent = bestNode;
                this.NodeRecordArray.AddToOpen(childNodeRecord);
            }
        }
Example #5
0
        protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            //this is where you process a child node
            var childNode  = GenerateChildNodeRecord(parentNode, connectionEdge);
            var openNode   = Open.SearchInOpen(childNode);
            var closedNode = Closed.SearchInClosed(childNode);

            if (openNode == null && closedNode == null)
            {
                Open.AddToOpen(childNode);
            }
            else if (openNode != null && openNode.fValue > childNode.fValue)
            {
                Open.Replace(openNode, childNode);
            }
            else if (closedNode != null && closedNode.fValue > childNode.fValue)
            {
                Closed.RemoveFromClosed(childNode);
                Open.AddToOpen(childNode);
            }
        }
        protected void ProcessChildNode(NodeRecord parent, NavigationGraphEdge connectionEdge, int connectionIndex)
        {
            var childNode = connectionEdge.ToNode;
            //TODO: implement the rest of your code here
            //this is where you process a child node
            var gValue = parent.gValue + (childNode.LocalPosition - parent.node.LocalPosition).magnitude;


            var childNodeRecord = new NodeRecord
            {
                node   = childNode,
                parent = parent,
                gValue = gValue,
                fValue = gValue
            };

            if (parent.parent == null)
            {
                childNodeRecord.StartNodeOutConnectionIndex = connectionIndex;
            }
            else
            {
                childNodeRecord.StartNodeOutConnectionIndex = parent.StartNodeOutConnectionIndex;
            }

            var openChildNode   = Open.SearchInOpen(childNodeRecord);
            var closedChildNode = Closed.SearchInClosed(childNodeRecord);

            if (openChildNode == null && closedChildNode == null)
            {
                Open.AddToOpen(childNodeRecord);
            }
            else if (openChildNode != null && openChildNode.fValue > childNodeRecord.fValue)
            {
                Open.Replace(openChildNode, childNodeRecord);
            }

            //TODO: Implement this method that processes a child node. Then you can use it in the Search method above.
        }
Example #7
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 OpenChild   = this.Open.SearchInOpen(childNode);
            var ClosedChild = this.Closed.SearchInClosed(childNode);

            if (OpenChild == null && ClosedChild == null)
            {
                this.Open.AddToOpen(childNode);
            }
            else if (OpenChild != null && OpenChild.fValue > childNode.fValue)
            {
                this.Open.Replace(OpenChild, childNode);
            }
            else if (ClosedChild != null && ClosedChild.fValue > childNode.fValue)
            {
                this.Closed.RemoveFromClosed(ClosedChild);
                this.Open.AddToOpen(childNode);
            }
        }
        protected override void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int connectionIndex)
        {
            TotalEdges++;
            NodeGoalBounds goalBound = GoalBoundingTable.table[parentNode.node.NodeIndex];

            if (goalBound != null && connectionIndex < goalBound.connectionBounds.Length)
            {
                DataStructures.GoalBounding.Bounds bound = goalBound.connectionBounds[connectionIndex];
                if (bound.PositionInsideBounds(GoalNode.Position))
                {
                    base.ProcessChildNode(parentNode, connectionEdge, connectionIndex);
                    return;
                }
            }
            else
            {
                base.ProcessChildNode(parentNode, connectionEdge, connectionIndex);
                return;
            }

            DiscardedEdges++;
            return;
        }
Example #9
0
        protected override void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            //TODO: Implement this method for the GoalBoundingPathfinding to Work. If you implemented the NodeArrayAStar properly, you wont need to change the search method.
            //Fetching index of GoalBoundingTable
            int            index      = parentNode.node.NodeIndex;
            NodeGoalBounds nodeBounds = GoalBoundingTable.table[index];

            if (nodeBounds == null) //Special check for some nodes that have null nodeBounds.
            {
                base.ProcessChildNode(parentNode, connectionEdge, edgeIndex);
            }
            if (nodeBounds != null && nodeBounds.connectionBounds.Length > edgeIndex) // Special check for when bounds are not available for the node even if it exists.
            {
                //Obtain the parent bound corresponding to the edgeIndex of the child.
                DataStructures.GoalBounding.Bounds b = nodeBounds.connectionBounds[edgeIndex];
                if (!b.PositionInsideBounds(GoalPosition))
                {
                    this.DiscardedEdges++;
                    return;
                }
            }
            base.ProcessChildNode(parentNode, connectionEdge, edgeIndex);
        }
        protected void ProcessChildNode(NodeRecord parent, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            var childNode       = connectionEdge.ToNode;
            var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode);

            this.UpdateBoundingBoxes(childNodeRecord, edgeIndex);

            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 = parent,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }
            else
            {
                NodeStatus childStatus = childNodeRecord.status;

                float gValue = parent.gValue + (childNode.LocalPosition - parent.node.LocalPosition).magnitude;

                if (childStatus == NodeStatus.Unvisited)
                {
                    this.NodeRecordArray.AddToOpen(UpdateChildNodeRecord(childNodeRecord, parent, gValue));
                }
                else if (gValue < childNodeRecord.gValue && childStatus == NodeStatus.Open)
                {
                    this.NodeRecordArray.Replace(childNodeRecord, UpdateChildNodeRecord(childNodeRecord, parent, gValue));
                }
            }
        }
        //don't forget to add the override keyword here if you define a ProcessChildNode method in the base class
        protected void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            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 you algorithm wont work
                childNodeRecord = new NodeRecord
                {
                    node = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            childNodeRecord.gValue = bestNode.gValue + connectionEdge.Cost;
            childNodeRecord.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 override void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            TotalEdges++;
            var childNode       = connectionEdge.ToNode;
            var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode);

            if (this.StartNode.Equals(parentNode.node) || this.StartNode.Equals(childNode))
            {
                base.ProcessChildNode(parentNode, connectionEdge, edgeIndex);
                return;
            }

            if (this.GoalNode.Equals(childNodeRecord.node) || this.GoalNode.Equals(childNode))
            {
                base.ProcessChildNode(parentNode, connectionEdge, edgeIndex);
                return;
            }

            this.dikjstra.StartNode = parentNode.node;

            if (nodeBounds == null)
            {
                //null entries on table are processed as normal A*
                base.ProcessChildNode(parentNode, connectionEdge, edgeIndex);
                return;
            }

            if (edgeIndex < nodeBounds.connectionBounds.Length)
            {
                if (nodeBounds.connectionBounds[edgeIndex].PositionInsideBounds(GoalPosition))
                {
                    base.ProcessChildNode(parentNode, connectionEdge, edgeIndex);
                    return;
                }
            }
            DiscardedEdges++;
        }
Example #13
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 #14
0
        protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            //this is where you process a child node
            var childNode  = GenerateChildNodeRecord(bestNode, connectionEdge);
            var openNode   = this.Open.SearchInOpen(childNode);
            var closedNode = this.Closed.SearchInClosed(childNode);

            if (openNode == null && closedNode == null)
            {
                this.Open.AddToOpen(childNode);
            }
            else if (openNode != null)
            {
                if (openNode.fValue > childNode.fValue || (openNode.fValue == childNode.fValue && openNode.hValue > childNode.hValue))
                {
                    this.Open.Replace(openNode, childNode);
                }
            }
            else if (closedNode != null && closedNode.fValue > childNode.fValue)
            {
                this.Closed.RemoveFromClosed(closedNode);
                this.Open.AddToOpen(childNode);
            }
        }
        protected virtual void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            NodeRecord childNode = GenerateChildNodeRecord(parentNode, connectionEdge);

            NodeRecord openNode = this.Open.SearchInOpen(childNode);

            if (openNode != null)
            {
                int comparison = childNode.fValue.CompareTo(openNode.fValue);
                if (comparison > 0)
                {
                    return;
                }

                if (comparison < 0 || childNode.hValue < openNode.hValue)
                {
                    this.Open.Replace(openNode, childNode);
                }
            }
            else if (this.Closed.SearchInClosed(childNode) == null)
            {
                this.Open.AddToOpen(childNode);
            }
        }
        //don't forget to add the override keyword here if you define a ProcessChildNode method in the base class
        protected void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {

            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 you algorithm wont work
                childNodeRecord = new NodeRecord
                {
                    node = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            var nodeInOpen = NodeRecordArray.SearchInOpen(childNode, childNodeRecord);

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

            if (childNodeRecord.status == NodeStatus.Unvisited || childNodeRecord.fValue > f)
            {
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;
                childNodeRecord.parent = bestNode;

                if (childNodeRecord.status == NodeStatus.Unvisited)
                {
                    this.NodeRecordArray.AddToOpen(childNode, childNodeRecord);
                    partialMaxOpenNodes++;
                }
                else if (childNodeRecord.status == NodeStatus.Open)
                {
                    this.NodeRecordArray.Replace(nodeInOpen, childNodeRecord);
                }
                else if (childNodeRecord.status == NodeStatus.Closed)
                {
                    this.NodeRecordArray.RemoveFromClosed(childNode, childNodeRecord);
                    this.NodeRecordArray.AddToOpen(childNode, childNodeRecord);
                }

            }

        }
Example #17
0
        protected virtual LocationRecord GenerateChildNodeRecord(LocationRecord parent, NavigationGraphEdge connectionEdge)
        {
            var childNodeRecord = new LocationRecord
            {
                Location = connectionEdge.ToNode
            };

            return childNodeRecord;
        }
        protected new void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            float f;
            float g;
            float h;

            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
                childNodeRecord = new NodeRecord
                {
                    node   = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }


            // implement the rest of your code here

            if (childNodeRecord.status == NodeStatus.Closed)
            {
                return;
            }

            float influenceCost = CalculateInfluenceCost(bestNode.node, childNode);

            if (influenceCost < 0.0f)
            {
                return;
            }

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

            if (childNodeRecord.status == NodeStatus.Open)
            {
                if (f <= childNodeRecord.fValue)
                {
                    childNodeRecord.gValue = g;
                    childNodeRecord.hValue = h;
                    childNodeRecord.fValue = f;
                    childNodeRecord.parent = bestNode;
                    this.NodeRecordArray.Replace(childNodeRecord, childNodeRecord);
                }
            }
            else
            {
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;
                childNodeRecord.status = NodeStatus.Open;
                childNodeRecord.parent = bestNode;
                this.NodeRecordArray.AddToOpen(childNodeRecord);
            }
        }
 protected virtual bool CheckNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
 {
     return GoalBoundingManager.Instance.WithinBounds(bestNode.node, connectionEdge.ToNode, GoalPosition);
 }
        //don't forget to add the override keyword here if you define a ProcessChildNode method in the base class
        protected override void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            float f;
            float g;
            float h;
            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 you algorithm wont work
                childNodeRecord = new NodeRecord
                {
                    node   = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }


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



            var oldChildNodeOpen   = Open.SearchInOpen(childNodeRecord);
            var oldChildNodeClosed = Closed.SearchInClosed(childNodeRecord);

            if ((oldChildNodeClosed == null) && (oldChildNodeOpen == null))
            {
                childNodeRecord.parent = bestNode;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;

                Open.AddToOpen(childNodeRecord);
            }
            else if ((oldChildNodeOpen != null) && f < childNodeRecord.fValue)
            {
                childNodeRecord.parent = bestNode;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;

                Open.Replace(oldChildNodeOpen, childNodeRecord);
            }
            else if ((oldChildNodeClosed != null) && f < childNodeRecord.fValue)
            {
                childNodeRecord.parent = bestNode;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;

                Open.AddToOpen(childNodeRecord);
            }
        }
        //protected override void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        protected override void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge)
        {
            //TODO: Implement this method for the GoalBoundingPathfinding to Work. If you implemented the NodeArrayAStar properly, you wont need to change the search method.
            float f;
            float g;
            float h;

            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 = parentNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            //TODO: implement the rest of your code here

            //custo da sol ate agora (valor do no anterior mais a aresta do bestNode ate ao childnode)
            g = parentNode.gValue + connectionEdge.Cost;
            //funcao heuristica: melhor custo estimado de n ate a solucao (como AStarPathFinding)
            h = this.Heuristic.H(childNode, this.GoalNode);
            f = F(g, h);

            //indice da cor do rectangulo
            var color = childNodeRecord.StartNodeOutConnectionIndex;

            //indice startNode
            var startNode = childNodeRecord.node.NodeIndex;

            //entrada da tabela dos rectangulos
            //var bbox = this.goalBoundingTable.table[color].connectionBounds[startNode];
            bool inBounds;

            if (this.goalBoundingTable.table[startNode] != null)
            {
                var bbox = this.goalBoundingTable.table[startNode].connectionBounds[color];
                inBounds = bbox.PositionInsideBounds(childNodeRecord.node.Position);
            }
            else
            {
                inBounds = true;
            }


            if (childNodeRecord.status == NodeStatus.Unvisited && inBounds)
            {
                childNodeRecord.fValue = f;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.parent = parentNode;
                NodeRecordArray.AddToOpen(childNodeRecord);
            }
            else if (childNodeRecord.status == NodeStatus.Open && (childNodeRecord.fValue > f || (f == childNodeRecord.fValue && childNodeRecord.hValue > h)))
            {
                childNodeRecord.fValue = f;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.parent = parentNode;
                NodeRecordArray.Replace(childNodeRecord, childNodeRecord);
            }
            else if (childNodeRecord.status == NodeStatus.Closed && f < childNodeRecord.fValue)
            {
                childNodeRecord.fValue = f;
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.parent = parentNode;
                NodeRecordArray.RemoveFromClosed(childNodeRecord);
                NodeRecordArray.AddToOpen(childNodeRecord);
            }
        }
 protected override void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
 {
     //TODO: Implement this method for the GoalBoundingPathfinding to Work. If you implemented the NodeArrayAStar properly, you wont need to change the search method.
 }
        //protected override void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        protected override void ProcessChildNode(NodeRecord parentNode, NavigationGraphEdge connectionEdge, int edgeIndex)
        {
            //TODO: Implement this method for the GoalBoundingPathfinding to Work. If you implemented the NodeArrayAStar properly, you wont need to change the search method.
            float f;
            float g;
            float h;

            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 = parentNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            //TODO: implement the rest of your code here



            //indice da cor do rectangulo
            var color = edgeIndex;
            //indice startNode
            var startNode = parentNode.node.NodeIndex;

            //entrada da tabela dos rectangulos
            //var bbox = this.goalBoundingTable.table[color].connectionBounds[startNode];
            bool inBounds = false;

            if (this.goalBoundingTable.table[startNode] != null)
            {
                var nodeBounds = this.goalBoundingTable.table[startNode];
                if (color < nodeBounds.connectionBounds.Length)
                {
                    var bbox = nodeBounds.connectionBounds[color];
                    inBounds = bbox.PositionInsideBounds(childNodeRecord.node.Position);
                }
                else
                {
                    inBounds = true;
                }
            }
            else
            {
                inBounds = true;
            }

            if (!inBounds)
            {
                return;
            }
            base.ProcessChildNode(parentNode, connectionEdge, edgeIndex);
        }
        protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            var childNode = GenerateChildNodeRecord(bestNode, connectionEdge);

            NodeRecord nodeInOpen = Open.SearchInOpen(childNode);
            NodeRecord nodeInClosed = Closed.SearchInClosed(childNode);
            // if child state is not in open or in closed then insert in open
            if (nodeInOpen == null && nodeInClosed == null)
            {
                Open.AddToOpen(childNode);
            }
            else
            {
                // if child state is in open with higher F-value replace old one
                if (nodeInOpen != null && nodeInOpen.fValue > childNode.fValue)
                {
                    Open.Replace(nodeInOpen, childNode);
                }
                else
                {
                    // if child state is in close with higher F-value then delete old and add new to open
                    if (nodeInClosed != null && nodeInClosed.fValue > childNode.fValue)
                    {
                        Closed.RemoveFromClosed(nodeInClosed);
                        Open.AddToOpen(childNode);
                    }
                }
            }
        }
        protected void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            float f;
            float g;
            float h;

            var childNode = connectionEdge.ToNode;
            var fromNode  = connectionEdge.FromNode;

            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
                childNodeRecord = new NodeRecord
                {
                    node   = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            // implement the rest of your code here

            if (childNodeRecord.status == NodeStatus.Closed)
            {
                return;
            }

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

            LocationRecord dummyRecord = new LocationRecord()
            {
                Location = childNode
            };

            float redInfluence = 0f, greenInfluence = 0f;

            // gets the influences for the child node
            LocationRecord redRecord = AutonomousCharacter.RedInfluenceMap.Closed.SearchInClosed(dummyRecord);

            if (redRecord != null)
            {
                redInfluence = redRecord.Influence;
            }

            LocationRecord greenRecord = AutonomousCharacter.GreenInfluenceMap.Closed.SearchInClosed(dummyRecord);

            if (greenRecord != null)
            {
                greenInfluence = greenRecord.Influence;
            }

            dummyRecord = new LocationRecord()
            {
                Location = fromNode
            };

            // gets the influences for the origin node
            redRecord = AutonomousCharacter.RedInfluenceMap.Closed.SearchInClosed(dummyRecord);
            if (redRecord != null)
            {
                redInfluence += redRecord.Influence;
            }

            greenRecord = AutonomousCharacter.GreenInfluenceMap.Closed.SearchInClosed(dummyRecord);
            if (greenRecord != null)
            {
                greenInfluence += greenRecord.Influence;
            }

            // calculates the average value of the path
            greenInfluence /= 2;
            redInfluence   /= 2;

            // add the impact of the map's influence
            h += (greenInfluence - redInfluence) * AvoidanceMargin;

            f = F(g, h);

            if (childNodeRecord.status == NodeStatus.Open)
            {
                if (f <= childNodeRecord.fValue)
                {
                    childNodeRecord.gValue = g;
                    childNodeRecord.hValue = h;
                    childNodeRecord.fValue = f;
                    childNodeRecord.parent = bestNode;
                    this.NodeRecordArray.Replace(childNodeRecord, childNodeRecord);
                }
            }
            else
            {
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;
                childNodeRecord.status = NodeStatus.Open;
                childNodeRecord.parent = bestNode;
                this.NodeRecordArray.AddToOpen(childNodeRecord);
            }
        }
        private NodeRecord GenerateChildNodeRecord(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);

            return childNodeRecord;
        }
Example #27
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);
        }
        protected virtual NodeRecord GenerateChildNodeRecord(NodeRecord parent, NavigationGraphEdge connectionEdge)
        {
            var childNode = connectionEdge.ToNode;
            var childNodeRecord = new NodeRecord
            {
                node = childNode,
                parent = parent,
                gValue = parent.gValue + (childNode.LocalPosition-parent.node.LocalPosition).magnitude,
                hValue = this.Heuristic.H(childNode, this.GoalNode)
            };

            childNodeRecord.fValue = F(childNodeRecord);

            return childNodeRecord;
        }
        protected void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge)
        {
            float f;
            float g;
            float h;

            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
                childNodeRecord = new NodeRecord
                {
                    node = childNode,
                    parent = bestNode,
                    status = NodeStatus.Unvisited
                };
                this.NodeRecordArray.AddSpecialCaseNode(childNodeRecord);
            }

            // implement the rest of your code here

            if (childNodeRecord.status == NodeStatus.Closed) return;

            LocationRecord edgeFromLocRec = new LocationRecord(){
                Location = connectionEdge.FromNode
            };
            LocationRecord edgeToLocRec = new LocationRecord(){
                Location = connectionEdge.ToNode
            };
            float securityAverage = 0.0f;
            if (autonomousCharacter.SecurityMap.ContainsKey(edgeToLocRec) && autonomousCharacter.SecurityMap.ContainsKey(edgeFromLocRec))
            {
                securityAverage = (autonomousCharacter.SecurityMap[edgeFromLocRec] + autonomousCharacter.SecurityMap[edgeToLocRec]) * 0.5f;
            }

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

            if (childNodeRecord.status == NodeStatus.Open)
            {
                if (f <= childNodeRecord.fValue)
                {
                    childNodeRecord.gValue = g;
                    childNodeRecord.hValue = h;
                    childNodeRecord.fValue = f;
                    childNodeRecord.parent = bestNode;
                    this.NodeRecordArray.Replace(childNodeRecord,childNodeRecord);
                }
            }
            else
            {
                childNodeRecord.gValue = g;
                childNodeRecord.hValue = h;
                childNodeRecord.fValue = f;
                childNodeRecord.status = NodeStatus.Open;
                childNodeRecord.parent = bestNode;
                this.NodeRecordArray.AddToOpen(childNodeRecord);
            }
        }
Example #30
0
 protected void ProcessChildNode(NodeRecord parent, NavigationGraphEdge connectionEdge, int connectionIndex)
 {
     //TODO: Implement this method that processes a child node. Then you can use it in the Search method above.
 }
        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);
            }
        }
Example #32
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
 }
Example #33
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);
            }
        }