SlideShare a Scribd company logo
게임 인공지능
                                                    GameAI




                  실질적인 길 계획하기
                  By Changhoon Park
                  http://wawworld.me
                                       Last Update : 2011. 08. 28

11년 10월 13일 목요일
2

                  실질적인     NavGraph 구축       가시점
                  길 계획하기   Raven의 NavGraph   확장 지형
                           경로 계획자 클래스        NavMesh
                           노드경로/에지경로
                           난처한 상황                      By Changhoon Park
                                                             http://wawworld.me

11년 10월 13일 목요일
3

                  실질적인     NavGraph 구축       가시점
                  길 계획하기   Raven의 NavGraph   확장 지형
                           경로 계획자 클래스        NavMesh
                           노드경로/에지경로
                           난처한 상황                      By Changhoon Park
                                                             http://wawworld.me

11년 10월 13일 목요일
4

                  실질적인     NavGraph 구축       가시점
                  길 계획하기   Raven의 NavGraph   확장 지형
                           경로 계획자 클래스        NavMesh
                           노드경로/에지경로
                           난처한 상황                      By Changhoon Park
                                                             http://wawworld.me

11년 10월 13일 목요일
5

                  실질적인     NavGraph 구축       성긴 그래프
                  길 계획하기   Raven의 NavGraph   밀집 그래프
                           경로 계획자 클래스        아이템 추가
                           노드경로/에지경로         공간 분할
                           난처한 상황                     By Changhoon Park
                                                            http://wawworld.me

11년 10월 13일 목요일
6

                  실질적인     NavGraph 구축       성긴 그래프
                  길 계획하기   Raven의 NavGraph   밀집 그래프
                           경로 계획자 클래스        아이템 추가
                           노드경로/에지경로         공간 분할
                           난처한 상황                     By Changhoon Park
                                                            http://wawworld.me

11년 10월 13일 목요일
7

                  실질적인     NavGraph 구축       성긴 그래프
                  길 계획하기   Raven의 NavGraph   밀집 그래프
                           경로 계획자 클래스        아이템 추가
                           노드경로/에지경로         공간 분할
                           난처한 상황                     By Changhoon Park
                                                            http://wawworld.me

11년 10월 13일 목요일
8

                  실질적인     NavGraph 구축       성긴 그래프
                  길 계획하기   Raven의 NavGraph   밀집 그래프
                           경로 계획자 클래스        아이템 추가
                           노드경로/에지경로         공간 분할
                           난처한 상황                     By Changhoon Park
                                                            http://wawworld.me

11년 10월 13일 목요일
template <class extra_info = void*>
          class NavGraphNode : public GraphNode
          {
          protected:
             Vector2D m_vPosition;
             extra_info m_ExtraInfo;
          public:
             //ctors
             NavGraphNode():m_ExtraInfo(extra_info()){}
             NavGraphNode(int idx,Vector2D pos):GraphNode(idx),
                                                 m_vPosition(pos), m_ExtraInfo(extra_info()) {}
             virtual ~NavGraphNode(){}
             Vector2D Pos()const;
             void SetPos(Vector2D NewPosition);
             extra_info ExtraInfo()const;
             void SetExtraInfo(extra_info info);
          };




             9

                  실질적인        NavGraph 구축       성긴 그래프
                  길 계획하기      Raven의 NavGraph   밀집 그래프
                              경로 계획자 클래스        아이템 추가
                              노드경로/에지경로         공간 분할
                              난처한 상황                                                         By Changhoon Park
                                                                                                   http://wawworld.me

11년 10월 13일 목요일
class Raven_PathPlanner
             {
             private:
                  enum {no_closest_node_found = -1};
             private:
                  Raven_Bot* m_pOwner;
                  const Raven_Map::NavGraph& m_NavGraph;
                  Vector2D m_vDestinationPos;
                  int GetClosestNodeToPosition(Vector2D pos)const;
             public:
                  Raven_PathPlanner(Raven_Bot* owner);
                  bool CreatePathToPosition(Vector2D TargetPos, std::list<Vector2D>& path);
                  bool CreatePathToItem(unsigned int ItemType, std::list<Vector2D>& path);
             };




            10

                  실질적인      NavGraph 구축       특정 위치까지의 경로
                  길 계획하기    Raven의 NavGraph   어떤 아이템 타입까지의 경로
                            경로 계획차 클래스
                            노드경로/에지경로
                            난처한 상황                                                   By Changhoon Park
                                                                                              http://wawworld.me

11년 10월 13일 목요일
11

                  실질적인     NavGraph 구축       특정 위치까지의 경로
                  길 계획하기   Raven의 NavGraph   어떤 아이템 타입까지의 경로
                           경로 계획자 클래스
                           노드경로/에지경로
                           난처한 상황                              By Changhoon Park
                                                                     http://wawworld.me

11년 10월 13일 목요일
bool Raven_PathPlanner::CreatePathToPosition(Vector2D TargetPos,std::list<Vector2D>& path)
         {
           m_vDestinationPos = TargetPos;

             if (!m_pOwner()->GetWorld()->isPathObstructed(m_pOwner->Pos(), TargetPos,
                                                         m_pOwner->BRadius()))
             {
                   path.push_back(TargetPos);
                   return true;
             }

             int ClosestNodeToBot = GetClosestNodeToPosition(m_pOwner->Pos());
             if (ClosestNodeToBot == no_closest_node_found) {
                   return false;
             }




            12

                  실질적인       NavGraph 구축       특정 위치까지의 경로
                  길 계획하기     Raven의 NavGraph   어떤 아이템 타입까지의 경로
                             경로 계획자 클래스
                             노드경로/에지경로
                             난처한 상황                                                      By Changhoon Park
                                                                                                http://wawworld.me

11년 10월 13일 목요일
int ClosestNodeToTarget = GetClosestNodeToPosition(TargetPos);
             if (ClosestNodeToTarget == no_closest_node_found)
             {
                   return false;
             }

             typedef Graph_SearchAStar< Raven_Map::NavGraph, Heuristic_Euclid> AStar;
              AStar search(m_NavGraph, ClosestNodeToBot, ClosestNodeToTarget);
              std::list<int> PathOfNodeIndices = search.GetPathToTarget();
              if (!PathOfNodeIndices.empty()) {
                    ConvertIndicesToVectors(PathOfNodeIndices, path);
                    path.push_back(TargetPos);
                    return true;
              } else {
                    return false;
              }
         }




             13

                   실질적인       NavGraph 구축       특정 위치까지의 경로
                   길 계획하기     Raven의 NavGraph   어떤 아이템 타입까지의 경로
                              경로 계획자 클래스
                              노드경로/에지경로
                              난처한 상황                                                    By Changhoon Park
                                                                                              http://wawworld.me

11년 10월 13일 목요일
14

                  실질적인     NavGraph 구축       특정 위치까지의 경로
                  길 계획하기   Raven의 NavGraph   어떤 아이템 타입까지의 경로
                           경로 계획자 클래스
                           노드경로/에지경로
                           난처한 상황                              By Changhoon Park
                                                                     http://wawworld.me

11년 10월 13일 목요일
template <class graph_type, class termination_condition>
         class Graph_SearchDijkstra
         {
             /* OMITTED */
         };
         ========================================================================
         static bool isSatisfied(const graph_type& G, int target, int CurrentNodeIdx);
         ========================================================================
         if (NextClosestNode == m_iTarget) return; //if the target has been found exit
         ========================================================================

         //if the target has been found exit
         if (termination_condition::isSatisfied(m_Graph, m_iTarget, NextClosestNode))
         {
              m_iTarget = NextClosestNode;
              return;
         }




            15

                  실질적인       NavGraph 구축       특정 위치까지의 경로
                  길 계획하기     Raven의 NavGraph   어떤 아이템 타입까지의 경로
                             경로 계획자 클래스
                             노드경로/에지경로
                             난처한 상황                                                     By Changhoon Park
                                                                                              http://wawworld.me

11년 10월 13일 목요일
template <class trigger_type>
         class FindActiveTrigger
         {
         public:
            template <class graph_type>
            static bool isSatisfied(const graph_type& G, int target, int CurrentNodeIdx)
            {
                  bool bSatisfied = false;
                  const graph_type::NodeType& node = G.GetNode(CurrentNodeIdx);
                  if ((node.ExtraInfo() != NULL) && node.ExtraInfo()->isActive() &&
                      (node.ExtraInfo()->EntityType() == target) )
                  {
                        bSatisfied = true;
                  }
                  return bSatisfied;
            }
         };




            16

                  실질적인        NavGraph 구축        특정 위치까지의 경로
                  길 계획하기      Raven의 NavGraph    어떤 아이템 타입까지의 경로
                              경로 계획자 클래스
                              노드경로/에지경로
                              난처한 상황                                                       By Changhoon Park
                                                                                                 http://wawworld.me

11년 10월 13일 목요일
typedef FindActiveTrigger<Trigger<Raven_Bot> > term_con;
         typedef Graph_SearchDijkstra_TS<RavenMap::NavGraph, term_con> SearchDij;

         //instantiate the search
         SearchDij dij( G,                 // the graph
                          6,               // the source node
                          type_health);    // the item type we are searching for
         //grab the path
         std::list<int> path = dij.GetPathToTarget();




            17

                  실질적인      NavGraph 구축       특정 위치까지의 경로
                  길 계획하기    Raven의 NavGraph   어떤 아이템 타입까지의 경로
                            경로 계획자 클래스
                            노드경로/에지경로
                            난처한 상황                                                 By Changhoon Park
                                                                                         http://wawworld.me

11년 10월 13일 목요일
18

                  실질적인     NavGraph 구축
                  길 계획하기   Raven의 NavGraph
                           경로 계획자 클래스
                           노드경로/에지경로
                           난처한 상황            By Changhoon Park
                                                   http://wawworld.me

11년 10월 13일 목요일
class NavGraphEdge : public GraphEdge
         {
         public:
            //enumerate some behavior flags
            enum BehaviorType
            {
                 normal    = 1 << 0,
                 tippy_toe = 1 << 1,
                 swim      = 1 << 2,
                 crawl     = 1 << 3,
                 creep     = 1 << 4
            };
         protected:
            BehaviorType m_iBehavior; //the behavior associated with traversing this edge

              /* EXTRANEOUS DETAIL OMITTED */
         };



              19

                   실질적인     NavGraph 구축       주석이 달린 에지
                   길 계획하기   Raven의 NavGraph   경로 계획자 수정
                            경로 계획자 클래스        경로 부드럽게 하기
                            노드경로/에지경로         CPU오버헤드 줄이기
                            난처한 상황                                                By Changhoon Park
                                                                                        http://wawworld.me

11년 10월 13일 목요일
class PathEdge
         {
         private:
             //positions of the source and destination nodes this edge connects
             Vector2D m_vSource;
             Vector2D m_vDestination;
             int m_iBehavior; //the behavior associated with traversing this edge
         public:
             PathEdge(Vector2D Source, Vector2D Destination, int Behavior)
                       : m_vSource(Source), m_vDestination(Destination), m_iBehavior(Behavior) {}
             Vector2D Destination()const;
             void SetDestination(Vector2D NewDest);
             Vector2D Source()const;
             void SetSource(Vector2D NewSource);
             int Behavior()const;
         };




            20

                  실질적인       NavGraph 구축        주석이 달린 에지
                  길 계획하기     Raven의 NavGraph    경로 계획자 수정
                             경로 계획자 클래스         경로 부드럽게 하기
                             노드경로/에지경로          CPU오버헤드 줄이기
                             난처한 상황                                                          By Changhoon Park
                                                                                                    http://wawworld.me

11년 10월 13일 목요일
bool Raven_PathPlanner::CreatePathToPosition(Vector2D TargetPos, std::list<PathEdge>& path)
         {

             if (!m_pOwner()->GetWorld()->isPathObstructed(m_pOwner->Pos(), TargetPos, m_pOwner->BRadius())) {
                    path.push_back(PathEdge(m_pOwner->Pos(), TargetPos, NavGraphEdge::normal));
                    return true;
             }

             int ClosestNodeToBot = GetClosestNodeToPosition(m_pOwner->Pos());
             if (ClosestNodeToBot == no_closest_node_found) {
                    //no path possible
                    return false;
             }

            int ClosestNodeToTarget = GetClosestNodeToPosition(TargetPos);
             if (ClosestNodeToTarget == no_closest_node_found) {
                    //no path possible
                    return false;
             }




            21

                   실질적인         NavGraph 구축         주석이 달린 에지
                   길 계획하기       Raven의 NavGraph     경로 계획자 수정
                                경로 계획자 클래스          경로 부드럽게 하기
                                노드경로/에지경로           CPU오버헤드 줄이기
                                난처한 상황                                                                 By Changhoon Park
                                                                                                             http://wawworld.me

11년 10월 13일 목요일
//create an instance of the A* search class.
             typedef Graph_SearchAStar<Raven_Map::NavGraph, Heuristic_Euclid> AStar;
             AStar search(m_NavGraph, ClosestNodeToBot, ClosestNodeToTarget);
             path = search.GetPathAsPathEdges(); //grab the path as a list of PathEdges

             if (!path.empty()) {
                    path.push_front( PathEdge(m_pOwner->Pos(),
                                                path.front().GetSource(), NavGraphEdge::normal));
                    path.push_back(PathEdge(path.back().GetDestination(),
                                               TargetPos, NavGraphEdge::normal));
                    return true;
             } else {
                    return false; //no path found by the search
             }
         }




             22

                   실질적인         NavGraph 구축         주석이 달린 에지
                   길 계획하기       Raven의 NavGraph     경로 계획자 수정
                                경로 계획자 클래스          경로 부드럽게 하기
                                노드경로/에지경로           CPU오버헤드 줄이기
                                난처한 상황                                                              By Changhoon Park
                                                                                                          http://wawworld.me

11년 10월 13일 목요일
if (Bot.PathPlanner.CreatePathToPosition(destination, path))
         {
             PathEdge next = GetNextEdgeFromPath(path)
             switch(next.Behavior)
             {
                  case behavior_stealth:
                      set stealth mode
                      break
                  case behavior_swim
                      set swim mode
                      break
                      etc
             }
             Bot.MoveTo(NavGraph.GetNodePosition(next.To))
         }




            23

                  실질적인        NavGraph 구축       주석이 달린 에지
                  길 계획하기      Raven의 NavGraph   경로 계획자 수정
                              경로 계획자 클래스        경로 부드럽게 하기
                              노드경로/에지경로         CPU오버헤드 줄이기
                              난처한 상황                                    By Changhoon Park
                                                                              http://wawworld.me

11년 10월 13일 목요일
24

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
25

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
26

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
27

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
void Raven_PathPlanner::SmoothPathEdgesQuick(std::list<PathEdge>& path)
         {
            //create a couple of iterators and point them at the front of the path
            std::list<PathEdge>::iterator e1(path.begin()), e2(path.begin());
            ++e2; //increment e2 so it points to the edge following e1.
            while (e2 != path.end())
            {
                  //check for obstruction, adjust and remove the edges accordingly
                  if ( m_pOwner->canWalkBetween(e1->Source(), e2->Destination()) ) {
                       e1->SetDestination(e2->Destination());
                       e2 = path.erase(e2);
                  } else {
                       e1 = e2;
                       ++e2;
                  }
            }
         }




            28

                  실질적인       NavGraph 구축       주석이 달린 에지
                  길 계획하기     Raven의 NavGraph   경로 계획자 수정
                             경로 계획자 클래스        경로 부드럽게 하기
                             노드경로/에지경로         CPU오버헤드 줄이기
                             난처한 상황                                                    By Changhoon Park
                                                                                             http://wawworld.me

11년 10월 13일 목요일
29

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
void Raven_PathPlanner::SmoothPathEdgesPrecise(std::list<PathEdge>& path)
         {
            std::list<PathEdge>::iterator e1, e2;
            e1 = path.begin();
            while (e1 != path.end()) {
                   e2 = e1;
                   ++e2;
                   while (e2 != path.end()) {
                       if ( m_pOwner->canWalkBetween(e1->Source(), e2->Destination()) ) {
                             e1->SetDestination(e2->Destination());
                             e2 = path.erase(++e1, ++e2);
                             e1 = e2;
                             --e1;
                       } else {
                             ++e2;
                       }
                   }
                   ++e1;
            }
         }




            30

                  실질적인         NavGraph 구축         주석이 달린 에지
                  길 계획하기       Raven의 NavGraph     경로 계획자 수정
                               경로 계획자 클래스          경로 부드럽게 하기
                               노드경로/에지경로           CPU오버헤드 줄이기
                               난처한 상황                                                       By Changhoon Park
                                                                                                  http://wawworld.me

11년 10월 13일 목요일
31

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
template <class graph_type>
         std::vector<std::vector<int> > CreateAllPairsTable(const graph_type& G)
         {
            enum {no_path = -1};
            std::vector<int> row(G.NumNodes(), no_path);
            std::vector<std::vector<int> > shortest_paths(G.NumNodes(), row);

             for (int source=0; source<G.NumNodes(); ++source)
             {
                   Graph_SearchDijkstra<graph_type> search(G, source);
                   std::vector<const GraphEdge*> spt = search.GetSPT();




            32

                  실질적인       NavGraph 구축       주석이 달린 에지
                  길 계획하기     Raven의 NavGraph   경로 계획자 수정
                             경로 계획자 클래스        경로 부드럽게 하기
                             노드경로/에지경로         CPU오버헤드 줄이기
                             난처한 상황                                                By Changhoon Park
                                                                                         http://wawworld.me

11년 10월 13일 목요일
for (int target = 0; target<G.NumNodes(); ++target)
                  {
                        if (source == target) {
                              shortest_paths[source][target] = target;
                        } else {
                          int nd = target;
                          while ((nd != source) && (spt[nd] != 0))
                          {
                               shortest_paths[spt[nd]->From][target]= nd;
                               nd = spt[nd]->From;
                          }
                       }
                  } //next target node
             } //next source node
             return shortest_paths;
         }




             33

                   실질적인         NavGraph 구축         주석이 달린 에지
                   길 계획하기       Raven의 NavGraph     경로 계획자 수정
                                경로 계획자 클래스          경로 부드럽게 하기
                                노드경로/에지경로           CPU오버헤드 줄이기
                                난처한 상황                                      By Changhoon Park
                                                                                  http://wawworld.me

11년 10월 13일 목요일
34

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
template <class graph_type>
         std::vector<std::vector<double> > CreateAllPairsCostsTable(const graph_type& G)
         {
            std::vector<double> row(G.NumNodes(), 0.0);
            std::vector<std::vector<double> > PathCosts(G.NumNodes(), row);
            for (int source=0; source<G.NumNodes(); ++source)
            {
                  Graph_SearchDijkstra<graph_type> search(G, source);
                  for (int target = 0; target<G.NumNodes(); ++target)
                  {
                       if (source != target) {
                            PathCosts[source][target]= search.GetCostToNode(target);
                       }
                  }//next target node
            }//next source node
            return PathCosts;
         }




            35

                  실질적인       NavGraph 구축       주석이 달린 에지
                  길 계획하기     Raven의 NavGraph   경로 계획자 수정
                             경로 계획자 클래스        경로 부드럽게 하기
                             노드경로/에지경로         CPU오버헤드 줄이기
                             난처한 상황                                                        By Changhoon Park
                                                                                                 http://wawworld.me

11년 10월 13일 목요일
36

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
template <class graph_type, class heuristic>
         int Graph_SearchAStar_TS<graph_type, heuristic>::CycleOnce()
         {
             if (m_pPQ->empty()) {
                   return target_not_found;
             }
             int NextClosestNode = m_pPQ->Pop();
             m_ShortestPathTree[NextClosestNode] = m_SearchFrontier[NextClosestNode];
             if (NextClosestNode == m_iTarget) {
                   return target_found;
             }
             Graph::ConstEdgeIterator EdgeItr(m_Graph, NextClosestNode);
             for (const GraphEdge* pE=EdgeItr.beg(); !EdgeItr.end(); pE=EdgeItr.nxt() {
                   /* SAME AS IN PREVIOUS A* ALGORITHM */
             }
             return search_incomplete;
         }




            37

                  실질적인       NavGraph 구축       주석이 달린 에지
                  길 계획하기     Raven의 NavGraph   경로 계획자 수정
                             경로 계획자 클래스        경로 부드럽게 하기
                             노드경로/에지경로         CPU오버헤드 줄이기
                             난처한 상황                                                       By Changhoon Park
                                                                                                http://wawworld.me

11년 10월 13일 목요일
template <class edge_type>
         class Graph_SearchTimeSliced
         {
         public:
            enum SearchType{AStar, Dijkstra};
         private:
            SearchType m_SearchType;
         public:
            Graph_SearchTimeSliced(SearchType type):m_SearchType(type){}
            virtual ~Graph_SearchTimeSliced(){}
            virtual int CycleOnce()=0;
            virtual std::vector<const edge_type*> GetSPT()const=0;
            virtual double GetCostToTarget()const=0;
            virtual std::list<PathEdge> GetPathAsPathEdges()const=0;
            SearchType GetType()const{return m_SearchType;}
         };




            38

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                                          By Changhoon Park
                                                                                 http://wawworld.me

11년 10월 13일 목요일
class Raven_PathPlanner
         {
         private:
            Graph_SearchTimeSliced* m_pCurrentSearch;
            /* EXTRANEOUS DETAIL OMITTED */
         public:
            bool RequestPathToItem(unsigned int ItemType);
            bool RequestPathToTarget(Vector2D TargetPos);
            int CycleOnce()const;
            Path GetPath();
         };




            39

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                            By Changhoon Park
                                                                   http://wawworld.me

11년 10월 13일 목요일
int Raven_PathPlanner::CycleOnce()const
         {
             assert (m_pCurrentSearch &&
                        "<Raven_PathPlanner::CycleOnce>: No search object instantiated");
             int result = m_pCurrentSearch->CycleOnce();
             if (result == target_not_found) {
                   Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY,
                                             SENDER_ID_IRRELEVANT, m_pOwner->ID(),
                                             Msg_NoPathAvailable, NO_ADDITIONAL_INFO);
             } else if (result == target_found) {
                   void* pTrigger =
                   m_NavGraph.GetNode(m_pCurrentSearch->GetPathToTarget().back()).ExtraInfo();
                   Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY,
                                             SENDER_ID_IRRELEVANT, m_pOwner->ID(),
                                             Msg_PathReady, pTrigger);
             }
             return result;
         }




            40

                  실질적인      NavGraph 구축       주석이 달린 에지
                  길 계획하기    Raven의 NavGraph   경로 계획자 수정
                            경로 계획자 클래스        경로 부드럽게 하기
                            노드경로/에지경로         CPU오버헤드 줄이기
                            난처한 상황                                                       By Changhoon Park
                                                                                                 http://wawworld.me

11년 10월 13일 목요일
template <class path_planner>
         class PathManager
         {
         private:
            std::list<path_planner*> m_SearchRequests;
            unsigned int m_iNumSearchCyclesPerUpdate;
         public:
            PathManager(unsigned int NumCyclesPerUpdate);
            void UpdateSearches();
            void Register(path_planner* pPathPlanner);
            void UnRegister(path_planner* pPathPlanner);
         };




            41

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                           By Changhoon Park
                                                                  http://wawworld.me

11년 10월 13일 목요일
template <class path_planner>
         inline void PathManager<path_planner>::UpdateSearches()
         {
             int NumCyclesRemaining = m_iNumSearchCyclesPerUpdate;
             std::list<path_planner*>::iterator curPath = m_SearchRequests.begin();
             while (NumCyclesRemaining-- && !m_SearchRequests.empty())
             {
                   int result = (*curPath)->CycleOnce();
                   if ( (result == target_found) || (result == target_not_found) ) {
                         curPath = m_SearchRequests.erase(curPath);
                   }
                   else {
                         ++curPath;
                   }
                   if (curPath == m_SearchRequests.end()) {
                         curPath = m_SearchRequests.begin();
                   }
             }//end while
         }




            42

                  실질적인        NavGraph 구축        주석이 달린 에지
                  길 계획하기      Raven의 NavGraph    경로 계획자 수정
                              경로 계획자 클래스         경로 부드럽게 하기
                              노드경로/에지경로          CPU오버헤드 줄이기
                              난처한 상황                                                   By Changhoon Park
                                                                                             http://wawworld.me

11년 10월 13일 목요일
bool Raven_PathPlanner:: RequestPathToItem(unsigned int ItemType)
         {
           GetReadyForNewSearch();
           int ClosestNodeToBot = GetClosestNodeToPosition(m_pOwner->Pos());
           if (ClosestNodeToBot == no_closest_node_found) {
                 return false;
           }

             typedef FindActiveTrigger<Trigger<Raven_Bot> > term_con;
             typedef Graph_SearchDijkstra_TS<Raven_Map::NavGraph, term_con> DijSearch;
             m_pCurrentSearch = new DijSearch(m_pWorld->GetNavigationGraph(),
                                            ClosestNodeToBot, ItemType);
             m_pWorld->GetPathManager()->Register(this);
             return true;
         }




             43

                  실질적인      NavGraph 구축       주석이 달린 에지
                  길 계획하기    Raven의 NavGraph   경로 계획자 수정
                            경로 계획자 클래스        경로 부드럽게 하기
                            노드경로/에지경로         CPU오버헤드 줄이기
                            난처한 상황                                                 By Changhoon Park
                                                                                         http://wawworld.me

11년 10월 13일 목요일
44

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
45

                  실질적인     NavGraph 구축       주석이 달린 에지
                  길 계획하기   Raven의 NavGraph   경로 계획자 수정
                           경로 계획자 클래스        경로 부드럽게 하기
                           노드경로/에지경로         CPU오버헤드 줄이기
                           난처한 상황                          By Changhoon Park
                                                                 http://wawworld.me

11년 10월 13일 목요일
46

                  실질적인     NavGraph 구축
                  길 계획하기   Raven의 NavGraph
                           경로 계획자 클래스
                           노드경로/에지경로
                           난처한 상황            By Changhoon Park
                                                   http://wawworld.me

11년 10월 13일 목요일
47

                  실질적인     NavGraph 구축
                  길 계획하기   Raven의 NavGraph
                           경로 계획자 클래스
                           노드경로/에지경로
                           난처한 상황            By Changhoon Park
                                                   http://wawworld.me

11년 10월 13일 목요일
Edge next = GetNextEdgeFromPath(path)
         //in a simple navgraph the edge cost is the length of the edge
         ExpectedTimeToReachPos = next.cost / Bot.MaxSpeed
         //factor in a margin of error
         MarginOfError = 2.0;
         ExpectedTimeToReachPos += MarginOfError;




            48

                  실질적인     NavGraph 구축
                  길 계획하기   Raven의 NavGraph
                           경로 계획자 클래스
                           노드경로/에지경로
                           난처한 상황                                         By Changhoon Park
                                                                                http://wawworld.me

11년 10월 13일 목요일
49

                  실질적인     NavGraph 구축
                  길 계획하기   Raven의 NavGraph
                           경로 계획자 클래스
                           노드경로/에지경로
                           난처한 상황            By Changhoon Park
                                                   http://wawworld.me

11년 10월 13일 목요일

More Related Content

More from Hoseo University

목적이 부여된 에이전트 행동
목적이 부여된 에이전트 행동목적이 부여된 에이전트 행동
목적이 부여된 에이전트 행동
Hoseo University
 
FoundationKit
FoundationKitFoundationKit
FoundationKit
Hoseo University
 
프로젝트 구성
프로젝트 구성프로젝트 구성
프로젝트 구성
Hoseo University
 
구성(Composition)
구성(Composition)구성(Composition)
구성(Composition)
Hoseo University
 
Objective-C에서의 OOP
Objective-C에서의 OOPObjective-C에서의 OOP
Objective-C에서의 OOP
Hoseo University
 
Dt3160.01
Dt3160.01Dt3160.01
Dt3160.01
Hoseo University
 

More from Hoseo University (7)

목적이 부여된 에이전트 행동
목적이 부여된 에이전트 행동목적이 부여된 에이전트 행동
목적이 부여된 에이전트 행동
 
FoundationKit
FoundationKitFoundationKit
FoundationKit
 
프로젝트 구성
프로젝트 구성프로젝트 구성
프로젝트 구성
 
구성(Composition)
구성(Composition)구성(Composition)
구성(Composition)
 
Objective-C에서의 OOP
Objective-C에서의 OOPObjective-C에서의 OOP
Objective-C에서의 OOP
 
Dt2210.01.syllabus
Dt2210.01.syllabusDt2210.01.syllabus
Dt2210.01.syllabus
 
Dt3160.01
Dt3160.01Dt3160.01
Dt3160.01
 

실질적인 길 계획하기

  • 1. 게임 인공지능 GameAI 실질적인 길 계획하기 By Changhoon Park http://wawworld.me Last Update : 2011. 08. 28 11년 10월 13일 목요일
  • 2. 2 실질적인 NavGraph 구축 가시점 길 계획하기 Raven의 NavGraph 확장 지형 경로 계획자 클래스 NavMesh 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 3. 3 실질적인 NavGraph 구축 가시점 길 계획하기 Raven의 NavGraph 확장 지형 경로 계획자 클래스 NavMesh 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 4. 4 실질적인 NavGraph 구축 가시점 길 계획하기 Raven의 NavGraph 확장 지형 경로 계획자 클래스 NavMesh 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 5. 5 실질적인 NavGraph 구축 성긴 그래프 길 계획하기 Raven의 NavGraph 밀집 그래프 경로 계획자 클래스 아이템 추가 노드경로/에지경로 공간 분할 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 6. 6 실질적인 NavGraph 구축 성긴 그래프 길 계획하기 Raven의 NavGraph 밀집 그래프 경로 계획자 클래스 아이템 추가 노드경로/에지경로 공간 분할 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 7. 7 실질적인 NavGraph 구축 성긴 그래프 길 계획하기 Raven의 NavGraph 밀집 그래프 경로 계획자 클래스 아이템 추가 노드경로/에지경로 공간 분할 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 8. 8 실질적인 NavGraph 구축 성긴 그래프 길 계획하기 Raven의 NavGraph 밀집 그래프 경로 계획자 클래스 아이템 추가 노드경로/에지경로 공간 분할 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 9. template <class extra_info = void*> class NavGraphNode : public GraphNode { protected: Vector2D m_vPosition; extra_info m_ExtraInfo; public: //ctors NavGraphNode():m_ExtraInfo(extra_info()){} NavGraphNode(int idx,Vector2D pos):GraphNode(idx), m_vPosition(pos), m_ExtraInfo(extra_info()) {} virtual ~NavGraphNode(){} Vector2D Pos()const; void SetPos(Vector2D NewPosition); extra_info ExtraInfo()const; void SetExtraInfo(extra_info info); }; 9 실질적인 NavGraph 구축 성긴 그래프 길 계획하기 Raven의 NavGraph 밀집 그래프 경로 계획자 클래스 아이템 추가 노드경로/에지경로 공간 분할 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 10. class Raven_PathPlanner { private: enum {no_closest_node_found = -1}; private: Raven_Bot* m_pOwner; const Raven_Map::NavGraph& m_NavGraph; Vector2D m_vDestinationPos; int GetClosestNodeToPosition(Vector2D pos)const; public: Raven_PathPlanner(Raven_Bot* owner); bool CreatePathToPosition(Vector2D TargetPos, std::list<Vector2D>& path); bool CreatePathToItem(unsigned int ItemType, std::list<Vector2D>& path); }; 10 실질적인 NavGraph 구축 특정 위치까지의 경로 길 계획하기 Raven의 NavGraph 어떤 아이템 타입까지의 경로 경로 계획차 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 11. 11 실질적인 NavGraph 구축 특정 위치까지의 경로 길 계획하기 Raven의 NavGraph 어떤 아이템 타입까지의 경로 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 12. bool Raven_PathPlanner::CreatePathToPosition(Vector2D TargetPos,std::list<Vector2D>& path) { m_vDestinationPos = TargetPos; if (!m_pOwner()->GetWorld()->isPathObstructed(m_pOwner->Pos(), TargetPos, m_pOwner->BRadius())) { path.push_back(TargetPos); return true; } int ClosestNodeToBot = GetClosestNodeToPosition(m_pOwner->Pos()); if (ClosestNodeToBot == no_closest_node_found) { return false; } 12 실질적인 NavGraph 구축 특정 위치까지의 경로 길 계획하기 Raven의 NavGraph 어떤 아이템 타입까지의 경로 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 13. int ClosestNodeToTarget = GetClosestNodeToPosition(TargetPos); if (ClosestNodeToTarget == no_closest_node_found) { return false; } typedef Graph_SearchAStar< Raven_Map::NavGraph, Heuristic_Euclid> AStar; AStar search(m_NavGraph, ClosestNodeToBot, ClosestNodeToTarget); std::list<int> PathOfNodeIndices = search.GetPathToTarget(); if (!PathOfNodeIndices.empty()) { ConvertIndicesToVectors(PathOfNodeIndices, path); path.push_back(TargetPos); return true; } else { return false; } } 13 실질적인 NavGraph 구축 특정 위치까지의 경로 길 계획하기 Raven의 NavGraph 어떤 아이템 타입까지의 경로 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 14. 14 실질적인 NavGraph 구축 특정 위치까지의 경로 길 계획하기 Raven의 NavGraph 어떤 아이템 타입까지의 경로 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 15. template <class graph_type, class termination_condition> class Graph_SearchDijkstra { /* OMITTED */ }; ======================================================================== static bool isSatisfied(const graph_type& G, int target, int CurrentNodeIdx); ======================================================================== if (NextClosestNode == m_iTarget) return; //if the target has been found exit ======================================================================== //if the target has been found exit if (termination_condition::isSatisfied(m_Graph, m_iTarget, NextClosestNode)) { m_iTarget = NextClosestNode; return; } 15 실질적인 NavGraph 구축 특정 위치까지의 경로 길 계획하기 Raven의 NavGraph 어떤 아이템 타입까지의 경로 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 16. template <class trigger_type> class FindActiveTrigger { public: template <class graph_type> static bool isSatisfied(const graph_type& G, int target, int CurrentNodeIdx) { bool bSatisfied = false; const graph_type::NodeType& node = G.GetNode(CurrentNodeIdx); if ((node.ExtraInfo() != NULL) && node.ExtraInfo()->isActive() && (node.ExtraInfo()->EntityType() == target) ) { bSatisfied = true; } return bSatisfied; } }; 16 실질적인 NavGraph 구축 특정 위치까지의 경로 길 계획하기 Raven의 NavGraph 어떤 아이템 타입까지의 경로 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 17. typedef FindActiveTrigger<Trigger<Raven_Bot> > term_con; typedef Graph_SearchDijkstra_TS<RavenMap::NavGraph, term_con> SearchDij; //instantiate the search SearchDij dij( G, // the graph 6, // the source node type_health); // the item type we are searching for //grab the path std::list<int> path = dij.GetPathToTarget(); 17 실질적인 NavGraph 구축 특정 위치까지의 경로 길 계획하기 Raven의 NavGraph 어떤 아이템 타입까지의 경로 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 18. 18 실질적인 NavGraph 구축 길 계획하기 Raven의 NavGraph 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 19. class NavGraphEdge : public GraphEdge { public: //enumerate some behavior flags enum BehaviorType { normal = 1 << 0, tippy_toe = 1 << 1, swim = 1 << 2, crawl = 1 << 3, creep = 1 << 4 }; protected: BehaviorType m_iBehavior; //the behavior associated with traversing this edge /* EXTRANEOUS DETAIL OMITTED */ }; 19 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 20. class PathEdge { private: //positions of the source and destination nodes this edge connects Vector2D m_vSource; Vector2D m_vDestination; int m_iBehavior; //the behavior associated with traversing this edge public: PathEdge(Vector2D Source, Vector2D Destination, int Behavior) : m_vSource(Source), m_vDestination(Destination), m_iBehavior(Behavior) {} Vector2D Destination()const; void SetDestination(Vector2D NewDest); Vector2D Source()const; void SetSource(Vector2D NewSource); int Behavior()const; }; 20 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 21. bool Raven_PathPlanner::CreatePathToPosition(Vector2D TargetPos, std::list<PathEdge>& path) { if (!m_pOwner()->GetWorld()->isPathObstructed(m_pOwner->Pos(), TargetPos, m_pOwner->BRadius())) { path.push_back(PathEdge(m_pOwner->Pos(), TargetPos, NavGraphEdge::normal)); return true; } int ClosestNodeToBot = GetClosestNodeToPosition(m_pOwner->Pos()); if (ClosestNodeToBot == no_closest_node_found) { //no path possible return false; } int ClosestNodeToTarget = GetClosestNodeToPosition(TargetPos); if (ClosestNodeToTarget == no_closest_node_found) { //no path possible return false; } 21 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 22. //create an instance of the A* search class. typedef Graph_SearchAStar<Raven_Map::NavGraph, Heuristic_Euclid> AStar; AStar search(m_NavGraph, ClosestNodeToBot, ClosestNodeToTarget); path = search.GetPathAsPathEdges(); //grab the path as a list of PathEdges if (!path.empty()) { path.push_front( PathEdge(m_pOwner->Pos(), path.front().GetSource(), NavGraphEdge::normal)); path.push_back(PathEdge(path.back().GetDestination(), TargetPos, NavGraphEdge::normal)); return true; } else { return false; //no path found by the search } } 22 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 23. if (Bot.PathPlanner.CreatePathToPosition(destination, path)) { PathEdge next = GetNextEdgeFromPath(path) switch(next.Behavior) { case behavior_stealth: set stealth mode break case behavior_swim set swim mode break etc } Bot.MoveTo(NavGraph.GetNodePosition(next.To)) } 23 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 24. 24 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 25. 25 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 26. 26 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 27. 27 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 28. void Raven_PathPlanner::SmoothPathEdgesQuick(std::list<PathEdge>& path) { //create a couple of iterators and point them at the front of the path std::list<PathEdge>::iterator e1(path.begin()), e2(path.begin()); ++e2; //increment e2 so it points to the edge following e1. while (e2 != path.end()) { //check for obstruction, adjust and remove the edges accordingly if ( m_pOwner->canWalkBetween(e1->Source(), e2->Destination()) ) { e1->SetDestination(e2->Destination()); e2 = path.erase(e2); } else { e1 = e2; ++e2; } } } 28 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 29. 29 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 30. void Raven_PathPlanner::SmoothPathEdgesPrecise(std::list<PathEdge>& path) { std::list<PathEdge>::iterator e1, e2; e1 = path.begin(); while (e1 != path.end()) { e2 = e1; ++e2; while (e2 != path.end()) { if ( m_pOwner->canWalkBetween(e1->Source(), e2->Destination()) ) { e1->SetDestination(e2->Destination()); e2 = path.erase(++e1, ++e2); e1 = e2; --e1; } else { ++e2; } } ++e1; } } 30 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 31. 31 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 32. template <class graph_type> std::vector<std::vector<int> > CreateAllPairsTable(const graph_type& G) { enum {no_path = -1}; std::vector<int> row(G.NumNodes(), no_path); std::vector<std::vector<int> > shortest_paths(G.NumNodes(), row); for (int source=0; source<G.NumNodes(); ++source) { Graph_SearchDijkstra<graph_type> search(G, source); std::vector<const GraphEdge*> spt = search.GetSPT(); 32 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 33. for (int target = 0; target<G.NumNodes(); ++target) { if (source == target) { shortest_paths[source][target] = target; } else { int nd = target; while ((nd != source) && (spt[nd] != 0)) { shortest_paths[spt[nd]->From][target]= nd; nd = spt[nd]->From; } } } //next target node } //next source node return shortest_paths; } 33 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 34. 34 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 35. template <class graph_type> std::vector<std::vector<double> > CreateAllPairsCostsTable(const graph_type& G) { std::vector<double> row(G.NumNodes(), 0.0); std::vector<std::vector<double> > PathCosts(G.NumNodes(), row); for (int source=0; source<G.NumNodes(); ++source) { Graph_SearchDijkstra<graph_type> search(G, source); for (int target = 0; target<G.NumNodes(); ++target) { if (source != target) { PathCosts[source][target]= search.GetCostToNode(target); } }//next target node }//next source node return PathCosts; } 35 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 36. 36 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 37. template <class graph_type, class heuristic> int Graph_SearchAStar_TS<graph_type, heuristic>::CycleOnce() { if (m_pPQ->empty()) { return target_not_found; } int NextClosestNode = m_pPQ->Pop(); m_ShortestPathTree[NextClosestNode] = m_SearchFrontier[NextClosestNode]; if (NextClosestNode == m_iTarget) { return target_found; } Graph::ConstEdgeIterator EdgeItr(m_Graph, NextClosestNode); for (const GraphEdge* pE=EdgeItr.beg(); !EdgeItr.end(); pE=EdgeItr.nxt() { /* SAME AS IN PREVIOUS A* ALGORITHM */ } return search_incomplete; } 37 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 38. template <class edge_type> class Graph_SearchTimeSliced { public: enum SearchType{AStar, Dijkstra}; private: SearchType m_SearchType; public: Graph_SearchTimeSliced(SearchType type):m_SearchType(type){} virtual ~Graph_SearchTimeSliced(){} virtual int CycleOnce()=0; virtual std::vector<const edge_type*> GetSPT()const=0; virtual double GetCostToTarget()const=0; virtual std::list<PathEdge> GetPathAsPathEdges()const=0; SearchType GetType()const{return m_SearchType;} }; 38 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 39. class Raven_PathPlanner { private: Graph_SearchTimeSliced* m_pCurrentSearch; /* EXTRANEOUS DETAIL OMITTED */ public: bool RequestPathToItem(unsigned int ItemType); bool RequestPathToTarget(Vector2D TargetPos); int CycleOnce()const; Path GetPath(); }; 39 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 40. int Raven_PathPlanner::CycleOnce()const { assert (m_pCurrentSearch && "<Raven_PathPlanner::CycleOnce>: No search object instantiated"); int result = m_pCurrentSearch->CycleOnce(); if (result == target_not_found) { Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, SENDER_ID_IRRELEVANT, m_pOwner->ID(), Msg_NoPathAvailable, NO_ADDITIONAL_INFO); } else if (result == target_found) { void* pTrigger = m_NavGraph.GetNode(m_pCurrentSearch->GetPathToTarget().back()).ExtraInfo(); Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, SENDER_ID_IRRELEVANT, m_pOwner->ID(), Msg_PathReady, pTrigger); } return result; } 40 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 41. template <class path_planner> class PathManager { private: std::list<path_planner*> m_SearchRequests; unsigned int m_iNumSearchCyclesPerUpdate; public: PathManager(unsigned int NumCyclesPerUpdate); void UpdateSearches(); void Register(path_planner* pPathPlanner); void UnRegister(path_planner* pPathPlanner); }; 41 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 42. template <class path_planner> inline void PathManager<path_planner>::UpdateSearches() { int NumCyclesRemaining = m_iNumSearchCyclesPerUpdate; std::list<path_planner*>::iterator curPath = m_SearchRequests.begin(); while (NumCyclesRemaining-- && !m_SearchRequests.empty()) { int result = (*curPath)->CycleOnce(); if ( (result == target_found) || (result == target_not_found) ) { curPath = m_SearchRequests.erase(curPath); } else { ++curPath; } if (curPath == m_SearchRequests.end()) { curPath = m_SearchRequests.begin(); } }//end while } 42 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 43. bool Raven_PathPlanner:: RequestPathToItem(unsigned int ItemType) { GetReadyForNewSearch(); int ClosestNodeToBot = GetClosestNodeToPosition(m_pOwner->Pos()); if (ClosestNodeToBot == no_closest_node_found) { return false; } typedef FindActiveTrigger<Trigger<Raven_Bot> > term_con; typedef Graph_SearchDijkstra_TS<Raven_Map::NavGraph, term_con> DijSearch; m_pCurrentSearch = new DijSearch(m_pWorld->GetNavigationGraph(), ClosestNodeToBot, ItemType); m_pWorld->GetPathManager()->Register(this); return true; } 43 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 44. 44 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 45. 45 실질적인 NavGraph 구축 주석이 달린 에지 길 계획하기 Raven의 NavGraph 경로 계획자 수정 경로 계획자 클래스 경로 부드럽게 하기 노드경로/에지경로 CPU오버헤드 줄이기 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 46. 46 실질적인 NavGraph 구축 길 계획하기 Raven의 NavGraph 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 47. 47 실질적인 NavGraph 구축 길 계획하기 Raven의 NavGraph 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 48. Edge next = GetNextEdgeFromPath(path) //in a simple navgraph the edge cost is the length of the edge ExpectedTimeToReachPos = next.cost / Bot.MaxSpeed //factor in a margin of error MarginOfError = 2.0; ExpectedTimeToReachPos += MarginOfError; 48 실질적인 NavGraph 구축 길 계획하기 Raven의 NavGraph 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일
  • 49. 49 실질적인 NavGraph 구축 길 계획하기 Raven의 NavGraph 경로 계획자 클래스 노드경로/에지경로 난처한 상황 By Changhoon Park http://wawworld.me 11년 10월 13일 목요일