public Node(Node parent, float cost, Dictionary <string, int> allStates, GAction action) { this.parent = parent; this.cost = cost; this.state = new Dictionary <string, int>(allStates); this.action = action; }
private List <GAction> ActionSubset(List <GAction> actions, GAction removeMe) { List <GAction> subset = new List <GAction>(); foreach (GAction a in actions) { if (!a.Equals(removeMe)) { subset.Add(a); } } return(subset); }
public Node(Node parent, float cost, Dictionary <string, int> allStates, Dictionary <string, int> beliefStates, GAction action) { this.parent = parent; this.cost = cost; this.state = new Dictionary <string, int>(allStates); foreach (KeyValuePair <string, int> p in beliefStates) { if (!this.state.ContainsKey(p.Key)) { this.state.Add(p.Key, p.Value); } } this.action = action; }
private void LateUpdate() { if (currentAction != null && currentAction.running) { float distanceToTarget = Vector3.Distance(currentAction.target.transform.position, this.transform.position); if (currentAction.agent.hasPath && distanceToTarget < 2f) { if (!invoked) { Invoke(nameof(CompleteAction), currentAction.duration); invoked = true; } } return; } if (planner == null || actionQueue == null) { planner = new GPlanner(); var sortedGoals = from entry in goals orderby entry.Value descending select entry; foreach (KeyValuePair <SubGoal, int> sg in sortedGoals) { actionQueue = planner.Plan(actions, sg.Key.sgoals, beliefs); if (actionQueue != null) { currentGoal = sg.Key; break; } } } if (actionQueue != null && actionQueue.Count == 0) { if (currentGoal.remove) { goals.Remove(currentGoal); } planner = null; } if (actionQueue != null && actionQueue.Count > 0) { currentAction = actionQueue.Dequeue(); if (currentAction.PrePerform()) { if (currentAction.target == null && currentAction.targetTag != "") { currentAction.target = GameObject.FindWithTag(currentAction.targetTag); } if (currentAction.target == null) { Debug.Log("Idiot"); } if (currentAction.target != null) { currentAction.running = true; //Debug.Log($"Setting DESTINATION OF {this.name} TO {currentAction.target.name} "); currentAction.agent.SetDestination(currentAction.target.transform.position); } } else { actionQueue = null; } } }