Exemplo n.º 1
0
        public void Update(GameTime gameTime, List <Controller> AllControllers, SpawnRateController.DataPoint Statistics)
        {
            List <Unit_KDTree> EnemyTrees = new List <Unit_KDTree>();

            for (int i = 0; i < AllControllers.Count; i++)
            {
                if (AllControllers[i].Allegiance != Allegiance)
                {
                    EnemyTrees.Add(AllControllers[i].SpatialTree);
                }
            }
            for (int i = 0; i < units.Count; i++)
            {
                units[i].Update(gameTime, EnemyTrees, SpatialTree);
                if (units[i].HitPoints <= 0.0)
                {
                    units.RemoveAt(i);
                }
            }
            spawnTimer -= gameTime.ElapsedGameTime.TotalSeconds;
            if (spawnTimer <= 0.0)
            {
                spawnTimer = Manager.GeneralSpawnTimer;
                units.Add(new Unit(Manager.terrain.GetRandomPosition()
                                   , (Unit.StatDistribution)MyGame.random.Next((int)Unit.StatDistribution.End)
                                   , (Unit.BehaviorType)MyGame.random.Next((int)Unit.BehaviorType.End)));
                SpatialTree = new Unit_KDTree(-1, units.ToArray());
            }
        }
Exemplo n.º 2
0
        public Manager(SpriteBatch spritebatch)
        {
            #region Drawing Initialization
            Manager.GameWindow  = new Rectangle(0, 0, MyGame.graphics.PreferredBackBufferWidth, MyGame.graphics.PreferredBackBufferHeight);
            Manager.spriteBatch = spritebatch;

            Kootenay16 = MyGame.content.Load <SpriteFont>("Kootenay16");

            Projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.PiOver4
                , MyGame.graphics.GraphicsDevice.Viewport.AspectRatio
                , 0.001f
                , 1000.0f);
            CameraFocus    = Vector3.Zero;
            CameraLocation = 1000.0f * Vector3.One;
            CameraUp       = Vector3.UnitY;
            View           = Matrix.CreateLookAt(
                CameraFocus + CameraLocation
                , CameraFocus
                , CameraUp);

            PreviousKeyboard = Keyboard.GetState();
            PreviousMouse    = Mouse.GetState();

            OrdinaryEffect    = MyGame.content.Load <Effect>("Effects\\Ordinary");
            TexturedEffect    = MyGame.content.Load <Effect>("Effects\\Textured");
            PostProcessEffect = MyGame.content.Load <Effect>("Effects\\PerlinNoise");

            BlankWhiteTexture = MyGame.content.Load <Texture2D>("Textures\\BlankBox");
            #endregion

            //Initialize the terrain
            terrain     = new Terrain(50.0f + 50.0f * (float)MyGame.random.NextDouble());
            CameraFocus = new Vector3(terrain.GridWidth * terrain.Scale / 2, 0.0f, terrain.GridHeight * terrain.Scale / 2);
            ClickPoint  = CameraFocus;

            //Initialize the unit controllers
            int NumControllers = MyGame.random.Next(5, 10);
            controllers = new List <Controller>();
            for (int i = 0; i < NumControllers; i++)
            {
                controllers.Add(new Controller());
            }

            //Initialize the scrolling bars
            DefaultHP      = new ScrollingBar(new Rectangle(GameWindow.Width - 205, 5, 200, 25), "Unit HP", 50.0, 500.0, 100.0);
            DefaultDamage  = new ScrollingBar(new Rectangle(GameWindow.Width - 205, 35, 200, 25), "Unit Damage", 1.0, 10.0, 2.0);
            DefaultSpeed   = new ScrollingBar(new Rectangle(GameWindow.Width - 205, 65, 200, 25), "Unit Speed", 0.0, 100.0, 25.0);
            DefaultRange   = new ScrollingBar(new Rectangle(GameWindow.Width - 205, 95, 200, 25), "Unit Range", 100.0, 2500.0, 500.0);
            ProcessingGoal = new ScrollingBar(new Rectangle(GameWindow.Width - 205, 125, 200, 25), "Allowable Lag", 2.5, 7.5, 5.0);

            //Initialize the statistics tracker
            LatestStatistics = new SpawnRateController.DataPoint();
        }
Exemplo n.º 3
0
        public void Update(GameTime gameTime)
        {
            if (IterationCounter == 0)
            {
                Statistics = new SpawnRateController.DataPoint();
            }
            //Print out the Machine Learning stats
            GeneralSpawnTimer = (1.0 - gameTime.ElapsedGameTime.TotalSeconds) * GeneralSpawnTimer
                                + gameTime.ElapsedGameTime.TotalSeconds * MyGame.rateController.RecommendedGeneralSpawnTimer;
            DebugText = "Spawn Rate: " + Math.Round(controllers.Count / GeneralSpawnTimer, 2) + " Units per Second";

            KeyboardState keyboard = Keyboard.GetState();
            MouseState    mouse    = Mouse.GetState();

            UpdateCamera(gameTime, keyboard, mouse);
            cursor.Update(mouse);
            //Update the scrolling bars for Units
            Unit.DefaultHP     = DefaultHP.Update(mouse);
            Unit.DefaultDamage = DefaultDamage.Update(mouse);
            Unit.DefaultSpeed  = (float)DefaultSpeed.Update(mouse);
            Unit.DefaultRange  = (float)DefaultRange.Update(mouse);
            SpawnRateController.OptimalProcessingTime = ProcessingGoal.Update(mouse);

            terrain.CalculateMousePosition();
            DateTime StartTime = DateTime.Now;
            int      UnitCount = 0;

            for (int i = 0; i < controllers.Count; i++)
            {
                controllers[i].Update(gameTime, controllers, Statistics);
                UnitCount += controllers[i].units.Count;
            }
            CalculateStatistics(UnitCount);
            Statistics.ProcessingTime += DateTime.Now.Subtract(StartTime).Milliseconds;
            DebugText += "\nTotal Units: " + UnitCount;
            if (MyGame.rateController.FittingError > 0)
            {
                DebugText += "\nFitting Error: " + Math.Round(MyGame.rateController.FittingError, 4);
                if (MyGame.rateController.TestError > 0)
                {
                    DebugText += "\nTest Error: " + Math.Round(MyGame.rateController.TestError, 4);
                }
                else
                {
                    DebugText += "\nNo Test Set currently";
                }
            }
            else
            {
                DebugText += "\nGathering Data..." + Math.Abs(MyGame.rateController.FittingError * 100) + "%";
            }

            PreviousKeyboard = keyboard;
            PreviousMouse    = mouse;

            IterationCounter++;
            if (IterationCounter >= 100)
            {
                IterationCounter = 0;
                MyGame.rateController.AddDataToQueue(Statistics, 100);
            }
        }