예제 #1
0
 public TestConfig(int pathDist, int nRuns, string output, PathfinderAlgorithm al)
 {
     avgPathDist = pathDist;
     nOfTestRuns = nRuns;
     outputFile  = output;
     algo        = al;
 }
예제 #2
0
 public TestConfig(int pathDist, int nRuns, string output, PathfinderAlgorithm al)
 {
     avgPathDist = pathDist;
     nOfTestRuns = nRuns;
     outputFile = output;
     algo = al;
 }
예제 #3
0
        /// <summary>
        /// Run button click event function. This function initializes the tests, and shows the testing window dialog.
        /// </summary>
        private void buttonRun_Click(object sender, EventArgs e)
        {
            if (ValidateInput())
            {
                // Check algorithm
                PathfinderAlgorithm algo = PathfinderAlgorithm.AStar;
                if (comboBoxAlgorithm.Text == "A*")
                {
                    algo = PathfinderAlgorithm.AStar;
                }
                else if (comboBoxAlgorithm.Text == "Dijkstra")
                {
                    algo = PathfinderAlgorithm.Dijkstra;
                }
                else if (comboBoxAlgorithm.Text == "Scent Map")
                {
                    algo = PathfinderAlgorithm.ScentMap;
                }

                // Set up the test configuration
                TestConfig config = new TestConfig(Convert.ToInt32(numericUpDownDist.Value),
                                                   Convert.ToInt32(numericUpDownNOfRuns.Text),
                                                   textBoxOutputFilename.Text, algo,
                                                   LevelHandler.Level.Map,
                                                   LevelHandler.Level.Map.Name);

                // Run Tests...
                TestRun test = new TestRun(config);
                test.ShowDialog();
                this.Close();
            }
        }
예제 #4
0
        public TestConfig(int pathDist, int nRuns, string output, PathfinderAlgorithm al, Map map, string mapName)
        {
            this.pathDist = pathDist;
            this.mapName  = mapName;
            nOfTestRuns   = nRuns;
            outputFile    = output;
            algo          = al;
            startTime     = DateTime.Now;
            endTime       = new DateTime();

            // Calculate number of obstacles
            nOfObstacles = 0;
            nOfObstacles = CalcNumberOfObstacles(map);
        }
예제 #5
0
        public TestConfig(int pathDist, int nRuns, string output, PathfinderAlgorithm al, Map map, string mapName)
        {
            this.pathDist = pathDist;
            this.mapName = mapName;
            nOfTestRuns = nRuns;
            outputFile = output;
            algo = al;
            startTime = DateTime.Now;
            endTime = new DateTime();

            // Calculate number of obstacles
            nOfObstacles = 0;
            nOfObstacles = CalcNumberOfObstacles(map);
        }
예제 #6
0
 /// <summary>
 /// Create a new pathfinder of the given type.
 /// </summary>
 /// <param name="algorithm">The type of algorithm the pathfinder should use.</param>
 /// <param name="gridSize">The grid size the pathfinder is to work with.</param>
 /// <returns></returns>
 public static Pathfinder CreatePathfinder(PathfinderAlgorithm algorithm, int gridSize, Map map)
 {
     switch (algorithm)
     {
         case PathfinderAlgorithm.Dijkstra:
             return (Pathfinder)new Dijkstra(gridSize, map);
         case PathfinderAlgorithm.AStar:
             return (Pathfinder)new AStar(gridSize, map);
         case PathfinderAlgorithm.ScentMap:
             return (Pathfinder)new ScentMap(gridSize, map);
         default:
             Console.WriteLine("PathfinderFactory: Attempted to create unrecognized pathfinder type. Returning Dijkstra.\n");
             return (Pathfinder)new Dijkstra(gridSize, map);
     }
 }
예제 #7
0
 private void SetBotType(PathfinderAlgorithm algorithm)
 {
     if (algorithm == PathfinderAlgorithm.Dijkstra || algorithm == PathfinderAlgorithm.AStar)
     {
         bot = new AiBotDijkstra(bot.Texture, bot.GridPosition.X, bot.GridPosition.Y);
     }
     else if (algorithm == PathfinderAlgorithm.ScentMap)
     {
         bot = new AiBotScent(bot.Texture, bot.GridPosition.X, bot.GridPosition.Y);
     }
     else
     {
         Console.WriteLine("Could not set bot type, unrecognized algorithm.");
     }
 }
예제 #8
0
        /// <summary>
        /// Create a new pathfinder of the given type.
        /// </summary>
        /// <param name="algorithm">The type of algorithm the pathfinder should use.</param>
        /// <param name="gridSize">The grid size the pathfinder is to work with.</param>
        /// <returns></returns>
        public static IPathfinder CreatePathfinder(PathfinderAlgorithm algorithm, int gridSize, Map map)
        {
            switch (algorithm)
            {
            case PathfinderAlgorithm.Dijkstra:
                return((IPathfinder) new Dijkstra(gridSize, map));

            case PathfinderAlgorithm.AStar:
                return((IPathfinder) new AStar(gridSize, map));

            case PathfinderAlgorithm.ScentMap:
                return((IPathfinder) new ScentMap(gridSize, map));

            default:
                Console.WriteLine("PathfinderFactory: Attempted to create unrecognized pathfinder type. Returning Dijkstra.\n");
                return((IPathfinder) new Dijkstra(gridSize, map));
            }
        }
예제 #9
0
        public static TestResult RunTest(PathfinderAlgorithm algorithm, Coord2 startPos, Coord2 targetPos)
        {
            // Set the pathfinding algorithm
            Level.SetPathfindingAlgorithm(algorithm);

            // Get Start Time
            DateTime startTime = DateTime.Now;

            // Find Path
            Level.Map.pathfinder.Build(startPos, targetPos);

            // Calculate time taken
            DateTime finishTime = DateTime.Now;
            TimeSpan timeTaken  = finishTime - startTime;

            // Return results
            return(new TestResult(timeTaken.Ticks, Level.Map.pathfinder.GetPath().Count));
        }
예제 #10
0
        public static TestResult RunTest(PathfinderAlgorithm algorithm, Coord2 startPos, Coord2 targetPos)
        {
            // Set the pathfinding algorithm
            Level.SetPathfindingAlgorithm(algorithm);

            // Get Start Time
            DateTime startTime = DateTime.Now;

            // Find Path
            Level.Map.pathfinder.Build(startPos, targetPos);

            // Calculate time taken
            DateTime finishTime = DateTime.Now;
            TimeSpan timeTaken = finishTime - startTime;

            // Return results
            return new TestResult(timeTaken.Ticks, Level.Map.pathfinder.GetPath().Count);
        }
예제 #11
0
        /// <summary>
        /// Runs a test and returns the result.
        /// </summary>
        /// <param name="algorithm">The pathfinding algorithm to use.</param>
        /// <param name="startPos">The starting position to use for the test.</param>
        /// <param name="pathLength">The length in manhattan distance that the target position should be from the starting position.</param>
        /// <param name="rand">A seeded random number generator to used to calculate a target position.</param>
        /// <returns></returns>
        public static TestResult RunTest(PathfinderAlgorithm algorithm, Coord2 startPos, List <Coord2> possibleTargets)
        {
            // Initialize result collection
            TestResultCollection results = new TestResultCollection();

            // Set the pathfinding algorithm
            Level.SetPathfindingAlgorithm(algorithm);

            // Create time take variable
            TimeSpan timeTaken;

            // The target position
            Coord2 targetPos;

            do
            {
                // Find random target
                do
                {
                    targetPos = possibleTargets[rand.Next(0, possibleTargets.Count)];
                } while (!level.Map.ValidPosition(targetPos));

                // Get Start Time
                DateTime startTime = DateTime.Now;

                // Find Path
                Level.Map.pathfinder.Build(startPos, targetPos, true);

                // Calculate time taken
                DateTime finishTime = DateTime.Now;
                timeTaken = finishTime - startTime;
            } while (Level.Map.pathfinder.GetPath().Count() == 0); // If no path was found, try again

            // Return result
            return(new TestResult(timeTaken.Ticks, Level.Map.pathfinder.GetPath().Count(), Level.Map.pathfinder.NodesSearched()));
        }
예제 #12
0
 public static void SetPathfindingAlgorithm(PathfinderAlgorithm algorithm)
 {
     level.SetPathfindingAlgorithm(algorithm);
 }
예제 #13
0
 /// <summary>
 /// Set the current pathfinding algorithm.
 /// </summary>
 /// <param name="algorithm">The algorithm to use in pathfinding.</param>
 public void SetPathfinder(PathfinderAlgorithm algorithm)
 {
     this.algorithm = algorithm;
     pathfinder = PathfinderFactory.CreatePathfinder(algorithm, gridSize, this);
     Console.WriteLine("Map.cs: Pathfinding algorithm set to " + pathfinder.GetName() + ".\n");
 }
예제 #14
0
 public void SetPathfindingAlgorithm(PathfinderAlgorithm algorithm)
 {
     map.SetPathfinder(algorithm);
 }
예제 #15
0
 public void SetPathfindingAlgorithm(PathfinderAlgorithm algorithm)
 {
     map.SetPathfinder(algorithm);
 }
예제 #16
0
 /// <summary>
 /// Set the current pathfinding algorithm.
 /// </summary>
 /// <param name="algorithm">The algorithm to use in pathfinding.</param>
 public void SetPathfinder(PathfinderAlgorithm algorithm)
 {
     this.algorithm = algorithm;
     pathfinder     = PathfinderFactory.CreatePathfinder(algorithm, gridSize, this);
 }
예제 #17
0
 /// <summary>
 /// Set the current pathfinding algorithm.
 /// </summary>
 /// <param name="algorithm">The algorithm to use in pathfinding.</param>
 public void SetPathfinder(PathfinderAlgorithm algorithm)
 {
     this.algorithm = algorithm;
     pathfinder     = PathfinderFactory.CreatePathfinder(algorithm, gridSize, this);
     Console.WriteLine("Map.cs: Pathfinding algorithm set to " + pathfinder.GetName() + ".\n");
 }
예제 #18
0
        /// <summary>
        /// Runs a test and returns the result.
        /// </summary>
        /// <param name="algorithm">The pathfinding algorithm to use.</param>
        /// <param name="startPos">The starting position to use for the test.</param>
        /// <param name="pathLength">The length in manhattan distance that the target position should be from the starting position.</param>
        /// <param name="rand">A seeded random number generator to used to calculate a target position.</param>
        /// <returns></returns>
        public static TestResult RunTest(PathfinderAlgorithm algorithm, Coord2 startPos, List<Coord2> possibleTargets)
        {
            // Initialize result collection
            TestResultCollection results = new TestResultCollection();

            // Set the pathfinding algorithm
            Level.SetPathfindingAlgorithm(algorithm);

            // Create time take variable
            TimeSpan timeTaken;

            // The target position
            Coord2 targetPos;

            do
            {
                // Find random target
                do {
                    targetPos = possibleTargets[rand.Next(0, possibleTargets.Count)];
                } while (!level.Map.ValidPosition(targetPos));

                // Get Start Time
                DateTime startTime = DateTime.Now;

                // Find Path
                Level.Map.pathfinder.Build(startPos, targetPos, true);

                // Calculate time taken
                DateTime finishTime = DateTime.Now;
                timeTaken = finishTime - startTime;
            } while (Level.Map.pathfinder.GetPath().Count() == 0); // If no path was found, try again

            // Return result
            return new TestResult(timeTaken.Ticks, Level.Map.pathfinder.GetPath().Count(), Level.Map.pathfinder.NodesSearched());
        }
예제 #19
0
 public static void SetPathfindingAlgorithm(PathfinderAlgorithm algorithm)
 {
     level.SetPathfindingAlgorithm(algorithm);
 }
예제 #20
0
 /// <summary>
 /// Set the current pathfinding algorithm.
 /// </summary>
 /// <param name="algorithm">The algorithm to use in pathfinding.</param>
 public void SetPathfinder(PathfinderAlgorithm algorithm)
 {
     this.algorithm = algorithm;
     pathfinder = PathfinderFactory.CreatePathfinder(algorithm, gridSize, this);
 }
예제 #21
0
 private void SetBotType(PathfinderAlgorithm algorithm)
 {
     if (algorithm == PathfinderAlgorithm.Dijkstra || algorithm == PathfinderAlgorithm.AStar)
         bot = new AiBotDijkstra(bot.Texture, bot.GridPosition.X, bot.GridPosition.Y);
     else if (algorithm == PathfinderAlgorithm.ScentMap)
         bot = new AiBotScent(bot.Texture, bot.GridPosition.X, bot.GridPosition.Y);
     else
         Console.WriteLine("Could not set bot type, unrecognized algorithm.");
 }