コード例 #1
0
ファイル: Path.cs プロジェクト: wachel/goap_test
 public void Append(Path2 path)
 {
     actions.AddRange(path.actions);
     foreach (ActionBase action in path.actions)
     {
         cost += action.GetCost();
     }
 }
コード例 #2
0
ファイル: ActionTest2.cs プロジェクト: wachel/goap_test
 void Update()
 {
     Path2 path = Planner.GetPlanning(actions, agent, actionGoal, 50);
     //string pathString = "";
     //foreach (ActionBase action in path.actions) {
     //    pathString += "->" + action.GetType().Name;
     //}
     //Debug.Log("start" + pathString);
 }
コード例 #3
0
 public static Path2 GetPlanning(List <ActionBase> actions, Agent start, ActionBase goal, int maxCost)
 {
     if (goal.CheckCondition(start))
     {
         Path2 path = pathPool.New();
         path.Reset();
         path.Append(goal);
         return(path);
     }
     else
     {
         int        minCost     = 99999;
         ActionBase bestAction  = null;
         Path2      bestSubPath = null;
         foreach (ActionBase action in actions)
         {
             if (action.CheckCondition(start))
             {
                 if (action.GetCost() <= maxCost)
                 {
                     ActionBase.FunRevert funRevert = action.PerformEffect(start);
                     Path2 subPath = GetPlanning(actions, start, goal, maxCost - action.GetCost());
                     if (subPath != null)
                     {
                         int cost = action.GetCost() + subPath.Cost;
                         if (cost < minCost)
                         {
                             if (bestSubPath != null)
                             {
                                 pathPool.Recycle(bestSubPath);
                             }
                             minCost     = cost;
                             maxCost     = minCost;
                             bestAction  = action;
                             bestSubPath = subPath;
                         }
                         else
                         {
                             pathPool.Recycle(subPath);
                         }
                     }
                     funRevert(start);
                 }
             }
         }
         if (bestAction != null)
         {
             bestSubPath.AddHead(bestAction);
             return(bestSubPath);
         }
     }
     return(null);
 }
コード例 #4
0
ファイル: ActionTest2.cs プロジェクト: wachel/goap_test
        void Start()
        {
            agent.SetValue("has_weapon", false);
            agent.SetValue("bullet_num", 0);
            agent.SetValue("kill_enemy", 0);

            actions.Add(new ActionPickWeapon());
            actions.Add(new ActionBuyWeapon());
            actions.Add(new ActionBuyBullet());
            actions.Add(new ActionFire());

            actionGoal           = new ActionGoal();
            actionGoal.condition = (Agent a) => { return(a.GetIntValue("kill_enemy") == 2); };

            Path2  path       = Planner.GetPlanning(actions, agent, actionGoal, 50);
            string pathString = "";

            foreach (ActionBase action in path.actions)
            {
                pathString += "->" + action.GetType().Name;
            }
            Debug.Log("start" + pathString);
        }
コード例 #5
0
ファイル: ActionTest3.cs プロジェクト: wachel/goap_test
        void Start()
        {
            agent.hasWeapon = false;
            agent.bulletNum = 0;
            agent.killedNum = 0;

            actions.Add(new ActionPickWeapon3());
            actions.Add(new ActionBuyWeapon3());
            actions.Add(new ActionBuyBullet3());
            actions.Add(new ActionFire3());

            actionGoal           = new ActionGoal();
            actionGoal.condition = (Agent a) => { return(a.killedNum == 2); };

            Path2  path       = Planner.GetPlanning(actions, agent, actionGoal, 50);
            string pathString = "";

            foreach (ActionBase action in path.actions)
            {
                pathString += "->" + action.GetType().Name;
            }
            Debug.Log("start" + pathString);
        }