public TestConfig(int pathDist, int nRuns, string output, PathfinderAlgorithm al) { avgPathDist = pathDist; nOfTestRuns = nRuns; outputFile = output; algo = al; }
public TestConfig(int pathDist, int nRuns, string output, PathfinderAlgorithm al) { avgPathDist = pathDist; nOfTestRuns = nRuns; outputFile = output; algo = al; }
/// <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(); } }
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); }
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); }
/// <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); } }
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."); } }
/// <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)); } }
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)); }
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); }
/// <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())); }
public static void SetPathfindingAlgorithm(PathfinderAlgorithm algorithm) { level.SetPathfindingAlgorithm(algorithm); }
/// <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"); }
public void SetPathfindingAlgorithm(PathfinderAlgorithm algorithm) { map.SetPathfinder(algorithm); }
public void SetPathfindingAlgorithm(PathfinderAlgorithm algorithm) { map.SetPathfinder(algorithm); }
/// <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); }
/// <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"); }
/// <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()); }
public static void SetPathfindingAlgorithm(PathfinderAlgorithm algorithm) { level.SetPathfindingAlgorithm(algorithm); }
/// <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); }
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."); }