Exemplo n.º 1
0
        public void InitialiseGraph(int CellsUp, int CellsAcross, int pWidth, int pHeight)
        {
            m_iCellsX = CellsAcross;
            m_iCellsY = CellsUp;

            m_icxClient = pWidth;
            m_icyClient = pHeight;

            //initialize the terrain vector with normal terrain
            int numNodes = CellsUp * CellsAcross;

            m_TerrainType = new List <int>(numNodes);

            for (int i = 0; i < numNodes; i++)
            {
                m_TerrainType.Add((int)brush_type.normal);
            }

            m_Path    = new List <int>();
            m_SubTree = new List <NavGraphEdge>();

            m_dCellWidth  = (double)m_icxClient / (double)CellsAcross;
            m_dCellHeight = (double)m_icyClient / (double)CellsUp;

            //create the graph
            m_Graph = new SparseGraph(false);//not a digraph

            SparseGraph.Helper_CreateGrid(m_Graph, m_icxClient, m_icyClient, CellsUp, CellsAcross);

            m_CurrentAlgorithm = algorithm_type.none;
            m_dTimeTaken       = 0;
        }
Exemplo n.º 2
0
        public void CreateSearchPath(algorithm_type Algo)
        {
            //set current algorithm
            m_CurrentAlgorithm = Algo;

            //clear any existing path
            m_Path.Clear();
            m_SubTree.Clear();

            if (m_CurrentAlgorithm == algorithm_type.none)
                return;

            //create and start a timer
            HighResTimer tempTimer = new HighResTimer();

            tempTimer.Start();

            BaseGraphSearchAlgo SearchAlgo = null;

            //do the search
            switch (m_CurrentAlgorithm)
            {
                case algorithm_type.search_dfs:

                    SearchAlgo = new Graph_SearchDFS(m_Graph, m_iSourceCell, m_iTargetCell);
                    break;

                case algorithm_type.search_bfs:

                    SearchAlgo = new Graph_SearchBFS(m_Graph, m_iSourceCell, m_iTargetCell);
                    break;

                case algorithm_type.search_dijkstra:

                    SearchAlgo = new Graph_SearchDijkstra(m_Graph, m_iSourceCell, m_iTargetCell);
                    break;

                case algorithm_type.search_astar:

                    SearchAlgo = new Graph_SearchAStar(m_Graph, m_iSourceCell, m_iTargetCell, EuclidianDistance);
                    break;

                default:
                    throw new Exception("<PathFinder::CreateSearchPath>: algorithm_type does not exist");
            }

            tempTimer.Stop();

            //record the time taken  
            m_dTimeTaken = tempTimer.RunningTime;

            if (SearchAlgo != null)
            {
                //now grab the path (if one has been found)
                if (SearchAlgo.Found())
                {
                    m_Path = SearchAlgo.GetPathToTarget();
                }

                m_SubTree = SearchAlgo.GetSearchTree();

                m_dCostToTarget = SearchAlgo.GetCostToTarget();
            }
        }
Exemplo n.º 3
0
        public void InitialiseGraph(int CellsUp, int CellsAcross, int pWidth, int pHeight)
        {
            m_iCellsX = CellsAcross;
            m_iCellsY = CellsUp;

            m_icxClient = pWidth;
            m_icyClient = pHeight;

            //initialize the terrain vector with normal terrain
            int numNodes = CellsUp * CellsAcross;
            m_TerrainType = new List<int>(numNodes);

            for (int i = 0; i < numNodes; i++)
            {
                m_TerrainType.Add((int)brush_type.normal);
            }

            m_Path = new List<int>();
            m_SubTree = new List<NavGraphEdge>();

            m_dCellWidth = (double)m_icxClient / (double)CellsAcross;
            m_dCellHeight = (double)m_icyClient / (double)CellsUp;

            //create the graph
            m_Graph = new SparseGraph(false);//not a digraph

            SparseGraph.Helper_CreateGrid(m_Graph, m_icxClient, m_icyClient, CellsUp, CellsAcross);

            m_CurrentAlgorithm = algorithm_type.none;
            m_dTimeTaken = 0;
        }
Exemplo n.º 4
0
        public void CreateSearchPath(algorithm_type Algo)
        {
            //set current algorithm
            m_CurrentAlgorithm = Algo;

            //clear any existing path
            m_Path.Clear();
            m_SubTree.Clear();

            if (m_CurrentAlgorithm == algorithm_type.none)
            {
                return;
            }

            //create and start a timer
            HighResTimer tempTimer = new HighResTimer();

            tempTimer.Start();

            BaseGraphSearchAlgo SearchAlgo = null;

            //do the search
            switch (m_CurrentAlgorithm)
            {
            case algorithm_type.search_dfs:

                SearchAlgo = new Graph_SearchDFS(m_Graph, m_iSourceCell, m_iTargetCell);
                break;

            case algorithm_type.search_bfs:

                SearchAlgo = new Graph_SearchBFS(m_Graph, m_iSourceCell, m_iTargetCell);
                break;

            case algorithm_type.search_dijkstra:

                SearchAlgo = new Graph_SearchDijkstra(m_Graph, m_iSourceCell, m_iTargetCell);
                break;

            case algorithm_type.search_astar:

                SearchAlgo = new Graph_SearchAStar(m_Graph, m_iSourceCell, m_iTargetCell, EuclidianDistance);
                break;

            default:
                throw new Exception("<PathFinder::CreateSearchPath>: algorithm_type does not exist");
            }

            tempTimer.Stop();

            //record the time taken
            m_dTimeTaken = tempTimer.RunningTime;

            if (SearchAlgo != null)
            {
                //now grab the path (if one has been found)
                if (SearchAlgo.Found())
                {
                    m_Path = SearchAlgo.GetPathToTarget();
                }

                m_SubTree = SearchAlgo.GetSearchTree();

                m_dCostToTarget = SearchAlgo.GetCostToTarget();
            }
        }