public void Append(Path4 <T> path) { actions.AddRange(path.actions); foreach (ActionBase4 <T> action in path.actions) { value += action.GetValue(); } }
void Update() { Path4 <Agent4> path = Planner4 <Agent4> .GetPlanning(actions, agent, actionGoal, -50); Planner4 <Agent4> .pathPool.Recycle(path); //string pathString = ""; //foreach (ActionBase action in path.actions) { // pathString += "->" + action.GetType().Name; //} //Debug.Log("start" + pathString); }
public static Path4 <T> GetPlanning(List <ActionBase4 <T> > actions, T agent, ActionBase4 <T> goal, int minValue) { if (goal.CheckCondition(agent)) { Path4 <T> path = pathPool.New(); path.Reset(); path.Append(goal); return(path); } else { int maxValue = -99999; ActionBase4 <T> bestAction = null; Path4 <T> bestSubPath = null; foreach (ActionBase4 <T> action in actions) { if (action.CheckCondition(agent)) { if (action.GetValue() >= minValue) { T newAgent = action.PerformEffect(agent); Path4 <T> subPath = GetPlanning(actions, newAgent, goal, minValue - action.GetValue()); if (subPath != null) { int value = action.GetValue() + subPath.Value; if (value > maxValue) { if (bestSubPath != null) { pathPool.Recycle(bestSubPath); } maxValue = value; bestAction = action; bestSubPath = subPath; } else { pathPool.Recycle(subPath); } } } } } if (bestAction != null) { bestSubPath.AddHead(bestAction); return(bestSubPath); } } return(null); }
void Start() { agent.hasWeapon = false; agent.bulletNum = 0; agent.killedNum = 0; actions.Add(new ActionPickWeapon4()); actions.Add(new ActionBuyWeapon4()); actions.Add(new ActionBuyBullet4()); actions.Add(new ActionFire4()); actionGoal = new ActionGoal4(); actionGoal.condition = (Agent4 a) => { return(a.killedNum == 2); }; Path4 <Agent4> path = Planner4 <Agent4> .GetPlanning(actions, agent, actionGoal, -50); string pathString = ""; foreach (ActionBase4 <Agent4> action in path.actions) { pathString += "->" + action.GetType().Name; } Debug.Log("start" + pathString); }