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
        }