public Game1() { //constructor graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferHeight = BackBufferHeight; graphics.PreferredBackBufferWidth = BackBufferWidth; Window.Title = "Pathfinder"; Content.RootDirectory = "../../../Content"; //set frame rate TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / TargetFrameRate); //load level map level = new Level(); level.Loadmap("../../../Content/0.txt"); //instantiate bot and player objects player = new Player(1, 1); //bot = new AiBotPathFollower(38, 38); //bot = new AiBotStatic(38, 38); allBots = new List <AiBotBase>() { new AiBotStatic(38, 38), new AiBotStatic(38, 15), new AiBotStatic(15, 38), new AiBotStatic(15, 15), new AiBotStatic(5, 5), new AiBotStatic(38, 1), new AiBotStatic(1, 38), new AiBotStatic(35, 1), new AiBotStatic(1, 35), new AiBotStatic(5, 15), new AiBotStatic(15, 5), new AiBotStatic(10, 15), new AiBotStatic(15, 10), new AiBotStatic(25, 20), new AiBotStatic(20, 25), new AiBotStatic(12, 12), new AiBotStatic(1, 8), new AiBotStatic(8, 1), new AiBotStatic(32, 18), new AiBotStatic(18, 32) }; //allBots = new List<AiBotBase>() { new AiBotStatic(38, 38), new AiBotStatic(38, 15), new AiBotStatic(15, 38), new AiBotStatic(15, 15), new AiBotStatic(5, 5), new AiBotStatic(38, 1), new AiBotStatic(1, 38), new AiBotStatic(35, 1), new AiBotStatic(1, 35), new AiBotStatic(5, 15), new AiBotStatic(15, 5), new AiBotStatic(10, 15), new AiBotStatic(15, 10), new AiBotStatic(25, 20), new AiBotStatic(20, 25), new AiBotStatic(12, 12), new AiBotStatic(1, 8), new AiBotStatic(8, 1), new AiBotStatic(32, 18), new AiBotStatic(18, 32) }; foreach (AiBotBase b in allBots) { //b.Update(gameTime, level, player); b.Update(new GameTime(), level, player); } bot = allBots[0]; DoTest(); }
public Game1() { //constructor graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferHeight = BackBufferHeight; graphics.PreferredBackBufferWidth = BackBufferWidth; Window.Title = "Pathfinder - SHA12307610"; Content.RootDirectory = "../../../Content"; //set frame rate TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / TargetFrameRate); //load level map level = new Level(); level.Loadmap("../../../Content/5.txt"); //instantiate bot and player objects bot = new AiBotStatic(10, 20); player = new Player(30, 20); }
public Game1() { //program settings. Window.Title = "GAL11266257_CGP3001M_Assignment 2"; graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferHeight = BackBufferHeight; graphics.PreferredBackBufferWidth = BackBufferWidth; Content.RootDirectory = "../../../Content"; TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / TargetFrameRate); //loads map. level = new Level(); level.Loadmap("../../../Content/0.txt"); //loads player. player = new Player(125, 67); }
public Game1() { //constructor graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferHeight = BackBufferHeight; graphics.PreferredBackBufferWidth = BackBufferWidth; Window.Title = "Pathfinder"; Content.RootDirectory = "Content"; this.IsMouseVisible = true; this.IsFixedTimeStep = false; elapsedTime = 0; frameCounter = 0; FPS = 60; mouseState = Mouse.GetState(); lastMouseState = mouseState; mouseClickPos = new Coord2(-1, -1); scrollOffset = Vector2.Zero; textColour = Color.BlueViolet; //set frame rate TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / TargetFrameRate); //load level map level = new Level(); string mapName = mapNumber.ToString(); //mapName = "eighty"; level.Loadmap("Content/" + mapName + ".txt"); //instantiate bot and player objects BackBufferWidth = level.gridSquareSize * level.GridSizeX; BackBufferHeight = level.GridSizeY * level.GridSquareSize; graphics.PreferredBackBufferHeight = BackBufferHeight; graphics.PreferredBackBufferWidth = BackBufferWidth; graphics.ApplyChanges(); graphics.GraphicsDevice.Reset(); SetCharacters(); //bots = new List<AiBotBase>(); #if ASTARTEST string heuristic = "Euclidean"; StreamWriter r = new StreamWriter("astarTest-" + mapName + "-" + heuristic + ".txt"); r.WriteLine("A Star Test values with " + heuristic); r.WriteLine("Map size: {0}x{1}", level.GridSizeX, level.GridSizeY); r.WriteLine("Times per build, in ms"); AStar aStar = new AStar(level); aStar = new AStar(level); Stopwatch timer = new Stopwatch(); Coord2 start = new Coord2(1, 1); Coord2 end = new Coord2(level.GridSizeX-1, level.GridSizeY-1); for (int i = 0; i < 1000; i++) { timer.Restart(); aStar.Build(level, start, end, false, heuristic); timer.Stop(); r.WriteLine("{0:N3}", timer.Elapsed.TotalMilliseconds); } r.Close(); #endif #if DIJKSTRASTEST StreamWriter r = new StreamWriter("dijkstrasTest-" + mapName + ".txt"); string mapDescription = ""; r.WriteLine("Dijkstra's Test values"); r.WriteLine("Map size: {0}x{1}", level.GridSizeX, level.GridSizeY); r.WriteLine(mapDescription); r.WriteLine("Times per build, in ms"); Dijkstra dijkstras = new Dijkstra(level); dijkstras = new Dijkstra(level); Stopwatch timer = new Stopwatch(); AiBotAlgorithm bot = new AiBotAlgorithm(1, 1); Player player = new Player(level.GridSizeX - 1, level.GridSizeY - 1); for (int i = 0; i < 1000; i++) { timer.Restart(); dijkstras.Build(level, bot, player); timer.Stop(); r.WriteLine("{0:N3}", timer.Elapsed.TotalMilliseconds); } r.Close(); #endif #if PRECOMPUTETEST StreamWriter r = new StreamWriter("precomputeTest-" + mapName + ".txt"); string mapDescription = ""; r.WriteLine("Precompute's Test values"); r.WriteLine("Map size: {0}x{1}", level.GridSizeX, level.GridSizeY); r.WriteLine(mapDescription); r.WriteLine("Times per build, in ms"); Precompute precompute = new Precompute(mapName); precompute = new Precompute(mapName); Stopwatch timer = new Stopwatch(); AiBotAlgorithm bot = new AiBotAlgorithm(1, 1); Player player = new Player(level.GridSizeX - 1, level.GridSizeY - 1); for (int i = 0; i < 1; i++) { timer.Restart(); precompute.Calculate(level); timer.Stop(); r.WriteLine("{0:N3}", timer.Elapsed.TotalMilliseconds); } r.Close(); #endif }
private void DoTest() { List <string> results = new List <string>(); for (int algorithm = 0; algorithm < 4; algorithm++) { for (int i = 0; i < 3; i++) { string resultsThisTime = ""; switch (algorithm) { case 0: //dijkstra resultsThisTime = i.ToString() + " map with Dijkstra,"; break; case 1: //A* resultsThisTime = i.ToString() + " map with A*,"; break; case 2: //Pre-computed A* resultsThisTime = i.ToString() + " map with pre-computed A*,"; break; case 3: //Scent resultsThisTime = i.ToString() + " map with AvP Scent,"; break; } level.Loadmap("../../../Content/" + i.ToString() + ".txt"); for (int j = 0; j < 10; j++) { int time = 0; switch (algorithm) { case 0: //dijkstra time = level.dijkstra.Build(level, bot, player); resultsThisTime += time.ToString() + ","; break; case 1: //A* time = level.aStar.Build(level, bot, player); resultsThisTime += time.ToString() + ","; break; case 2: //Pre-computed A* break; case 3: //Scent break; } } results.Add(resultsThisTime); } } foreach (string s in results) { Debug.WriteLine(s); } }