public void RunPathfindingAlgorithm()
 {
     if (gameDataContainer.AlgorithmIndex == 0)
     {
         dijkstraPathfinding.FindPath(gameDataContainer.StartPosition, gameDataContainer.EndPosition);
     }
     else if (gameDataContainer.AlgorithmIndex == 1)
     {
         aStarPathfinding.FindPath(gameDataContainer.StartPosition, gameDataContainer.EndPosition);
     }
 }
Exemple #2
0
        public void Start()
        {
            while (m_done == false)
            {
                m_timer.Start(); //start
                m_timer.Stop();  //stop
                Console.WriteLine(m_timer.ElapsedMilliseconds);

                m_timer.Reset();

                m_timer.Restart(); //start
                m_timer.Stop();    //stop
                Console.WriteLine(m_timer.ElapsedMilliseconds);

                Console.WriteLine("Choose map, 1 or 2:");
                string input = Console.ReadLine();

                if (input == "1" || input == "2")
                {
                    //initialize the map and the pathfinders
                    m_map.LoadMap(Int32.Parse(input));
                    m_aStar      = new AStarPathfinding(ref m_map);
                    m_bruteForce = new BruteForce(ref m_map);

                    Console.WriteLine("Choose pathfinder, A* (1) or BruteForce (2):");
                    input = Console.ReadLine();

                    if (input == "1")
                    {
                        //use A*

                        m_timer.Reset();
                        for (int i = 0; i < m_numberOfLoops; i++)
                        {
                            m_timer.Start();//start
                            //find path
                            m_aStar.FindPath(m_map.m_start, m_map.m_goal);
                            m_timer.Stop();//stop
                        }

                        //set path
                        m_path = m_aStar.m_pathList;
                    }
                    else if (input == "2")
                    {
                        //use BruteForce

                        Console.WriteLine("Depth First:");
                        m_timer.Reset();
                        for (int i = 0; i < m_numberOfLoops; i++)
                        {
                            m_timer.Start();//start
                            //depth first
                            m_bruteForce.DepthFirst(m_map.m_start, m_map.m_goal);
                            m_timer.Stop();//stop
                        }
                        //set path
                        m_path = m_bruteForce.m_pathList;

                        //print the map
                        PrintMap();

                        //print the timer
                        PrintTimer(m_timer);


                        Console.WriteLine("Breadth First:");
                        m_timer.Reset();
                        for (int i = 0; i < m_numberOfLoops; i++)
                        {
                            m_timer.Start();//start
                            //breadth first
                            m_bruteForce.BreadthFirst(m_map.m_start, m_map.m_goal);
                            m_timer.Stop();//stop
                        }
                        //set path
                        m_path = m_bruteForce.m_pathList;
                    }

                    //print the map
                    PrintMap();

                    //print the timer
                    PrintTimer(m_timer);
                }

                Console.WriteLine();//adding an empty line at the end
            }
        }