Beispiel #1
0
 public AStarNode(IAStarState value, IAStarState goal, float cost, AStarMap map)
 {
     this.Cost      = cost;
     this.GScore    = float.MaxValue;
     this.Heuristic = float.MaxValue;
     this.Value     = value;
     this.CameFrom  = null;
     this.Goal      = goal;
     this.Heuristic = map.GetHeuristic(this);
 }
Beispiel #2
0
 public bool EqualState(IAStarState other)
 {
     if (other is GOAPNode)
     {
         return(((GOAPNode)other).WorldState.Equals(WorldState));
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
 public bool SatisfiedBy(IAStarState other)
 {
     if (other is GOAPNode)
     {
         return(((GOAPNode)other).WorldState.SatisfiedBy(WorldState));
     }
     else
     {
         return(false);
     }
 }
Beispiel #4
0
 /**
  *  Checks if two State objects represent the same state
  **/
 public bool EqualState(IAStarState other)
 {
     if (other is NavNode)
     {
         return(this.Position.Distance(((NavNode)other).Position) < error);
     }
     else
     {
         return(false);
     }
 }
Beispiel #5
0
        public IEnumerable <IAStarState> FindSolution(IAStarState start, IAStarState goal, AStarMap map)
        {
            //It should add to the goal state the preconditions of the action
            closedSet.Clear();
            openSet.Clear();
            AStarNode startNode = new AStarNode(start, goal, 0, map);

            startNode.Goal   = goal;
            startNode.GScore = 0;
            openSet.Add(startNode);
            AStarStateComparer comparer       = new AStarStateComparer();
            FScoreComparer     fscoreComparer = new FScoreComparer();

            while (openSet.Count > 0)
            {
                openSet.Sort(fscoreComparer);
                AStarNode current = openSet.First();
                openSet.Remove(current);
                if (current.Value.SatisfiedBy(current.Goal))
                {
                    return(reconstructPath(current));
                }
                closedSet.Add(current);
                foreach (AStarNode neighbour in map.GetNeighbours(current))
                {
                    if (closedSet.Contains(neighbour, comparer))
                    {
                        continue;
                    }
                    float tentativeGScore = current.GScore + neighbour.Cost;
                    if (openSet.Contains(neighbour, comparer) == false)
                    {
                        openSet.Add(neighbour);
                    }
                    else if (tentativeGScore >= neighbour.GScore)
                    {
                        continue;
                    }
                    neighbour.CameFrom = current;
                    neighbour.GScore   = tentativeGScore;
                    //FScore updates automatically
                }
            }
            return(null);
        }
Beispiel #6
0
 public bool SatisfiedBy(IAStarState other)
 {
     return(this.EqualState(other));
 }