Example #1
0
        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
        }
Example #2
0
 private void SetDijkstra()
 {
     Coord2 newPos = bots[0].GridPosition;
     if (bots[0].dijkstra == null)
         bots = new List<AiBotBase>();
     if (bots.Count == 0)
         bots.Add(new AiBotSimple(newPos.X, newPos.Y));
     player.EnableScent(false, level);
     for (int i = 0; i < bots.Count; i++)
     {
         bots[i] = new AiBotAlgorithm(bots[i].GridPosition.X, bots[i].GridPosition.Y);
         bots[i].dijkstra = new Dijkstra(level);
         bots[i].dijkstra.Build(level, bots[i], player);
         methodText = "Dijkstra's";
     }
 }
Example #3
0
        private void SetPrecompute()
        {
            Coord2 newPos = bots[0].GridPosition;
            if (level.precompute == null)
                bots = new List<AiBotBase>();
            if (bots.Count == 0)
                bots.Add(new AiBotSimple(newPos.X, newPos.Y));

            level.precompute = new Precompute(level.name);
            for (int i = 0; i < bots.Count; i++)
            {
                bots[i] = new AiBotAlgorithm(bots[i].GridPosition.X, bots[i].GridPosition.Y);
                //bots[i].precompute = new Precompute(level.name);
                //level.precompute.Calculate(level);
                level.precompute.FindPath(bots[i], player, level);

                bots[i].path = level.precompute.path;

                bots[i].path.Add(player.GridPosition);
                bots[i].path.Reverse();
                bots[i].path.Add(new Coord2(bots[i].GridPosition.X, bots[i].GridPosition.Y));
                bots[i].dijkstra = null;
                bots[i].aStar = null;
            }
            methodText = "Precomputed.";
        }
Example #4
0
        private void SetAStar()
        {
            Coord2 newPos = bots[0].GridPosition;
            if (bots[0].aStar == null)
                bots = new List<AiBotBase>();
            if (bots.Count == 0)
                bots.Add(new AiBotSimple(newPos.X, newPos.Y));
            for (int i = 0; i < bots.Count; i++)
            {
                bots[i].dijkstra = null;
                player.EnableScent(false, level);

                bots[i] = new AiBotAlgorithm(bots[i].GridPosition.X, bots[i].GridPosition.Y);
                bots[i].aStar = new AStar(level);
                bots[i].aStar.Build(level, bots[i].GridPosition, player.GridPosition, false, astarHeuristic);
                methodText = "A*";
            }
        }