Exemple #1
0
        //public AgentController AgentController
        //{
        //    get { return agent; }
        //    set { agent = value; }
        //}

        public void AddAgent(AgentController prevAgent)
        {
            Agent = prevAgent;
            Agent.Update(this);
        }
Exemple #2
0
        public static List <BlankGrid> FindPath(AgentController agent, BlankGrid destination, bool destinationEmpty) // how to handle destination containing something vs. being empty, or rather what to do when going to an object.
        {
            var startNode = agent.Cell;
            // if contains agent, then make "target node" check for something around it.
            HashSet <BlankGrid> closedSet = new HashSet <BlankGrid>();
            //Heap<PathfindingNode> openSet = new Heap<PathfindingNode>(agent.Parent.gridHeight * agent.Parent.gridWidth);
            List <BlankGrid> openSet = new List <BlankGrid>();

            openSet.Add(startNode);
            List <BlankGrid> targetNeighbors = GetMoveNeighbors(agent.Parent.GetStateInfo(agent.currentState), destination, new Tuple <int, int>(agent.Parent.gridWidth, agent.Parent.gridHeight));

            while (openSet.Count > 0)
            {
                //PathfindingNode currentNode = openSet.RemoveFirst();// for heap implementation
                BlankGrid currentNode = openSet[0];
                for (int i = 0; i < openSet.Count; i++)
                {
                    if (openSet[i].FCost < currentNode.FCost || openSet[i].FCost == currentNode.FCost && openSet[i].HCost < currentNode.HCost)
                    {
                        currentNode = openSet[i];
                    }
                }
                openSet.Remove(currentNode);
                // end list version
                closedSet.Add(currentNode);
                if (destinationEmpty)
                {
                    if (currentNode == destination)
                    {
                        return(RetracePath(startNode, currentNode));
                    }
                }
                else
                {
                    foreach (var targetNeighbor in targetNeighbors)
                    {
                        if (currentNode == targetNeighbor)
                        {
                            return(RetracePath(startNode, currentNode));
                        }
                    }
                }

                List <BlankGrid> neighbors = GetMoveNeighbors(agent.Parent.GetStateInfo(agent.currentState), currentNode, new Tuple <int, int>(agent.Parent.gridWidth, agent.Parent.gridHeight));

                foreach (var neighbor in neighbors)
                {
                    if (neighbor.ContainsAgent || closedSet.Contains(neighbor))
                    {
                        continue;
                    }
                    int newMovementCostToNeighbor = currentNode.GCost + GetDistance(currentNode, neighbor);
                    if (newMovementCostToNeighbor < neighbor.GCost || !openSet.Contains(neighbor))
                    {
                        neighbor.GCost      = newMovementCostToNeighbor;
                        neighbor.HCost      = GetDistance(neighbor, destination);
                        neighbor.PathParent = currentNode;
                        if (!openSet.Contains(neighbor))
                        {
                            openSet.Add(neighbor);
                        }
                        //else
                        //{
                        //    openSet[openSet.IndexOf(neighbor)]
                        //}
                    }
                }
            }
            return(null);
        }
Exemple #3
0
 public BlankGrid(int x, int y, AgentController agent, CA Parent) : this(x, y, Parent)
 {
     AddAgent(agent);
 }