Пример #1
0
        public override TankUpdate Update(IGameState gameState)
        {
            // Pick a random goal to defend
            if (_goalToDefend == null && gameState.Goals.Count > 0)
            {
                var shuffledGoals = gameState.Goals.OrderBy(a => Guid.NewGuid());
                _goalToDefend = shuffledGoals.First();
            }

            TankUpdate tankUpdate = new TankUpdate();

            if (gameState.Foes.Any() && gameState.Goals.Any())
            {
                if (_targetFoe == null || _targetFoe.Health <= 0)
                {
                    // Pick a random target
                    var shuffledFoes = gameState.Foes.OrderBy(a => Guid.NewGuid());
                    _targetFoe = shuffledFoes.First();
                }

                if (_targetFoe != null)
                {
                    // Target the foe's current location
                    tankUpdate.ShotTarget = _targetFoe.Center;
                }

                // Move toward tower
                tankUpdate.MovementTarget = LocationProvider.GetLocation(_goalToDefend.X, _goalToDefend.Y);
                tankUpdate.Bullet = new Bullet { Damage = 200, Freeze = 0, SplashRange = 0 };
            }

            return tankUpdate;
        }
Пример #2
0
        public override TankUpdate Update(IGameState gameState)
        {
            TankUpdate tankUpdate = new TankUpdate();

            if (gameState.Foes.Any() && gameState.Goals.Any())
            {
                tankUpdate.ShotTarget = LocationProvider.GetLocation(_xTarget, _yTarget);
                ChangeBulletPower(tankUpdate.ShotTarget, gameState);

                var range = GetDistanceFromTank(LocationProvider.GetLocation(_xTarget, _yTarget)) + 1;
                if (Bullet.GetReloadTime((int)range) < 1000 || range < 100)
                {
                    tankUpdate.Bullet = Bullet;
                }
                else
                {
                    tankUpdate.Bullet = new Bullet();
                }

                UpdateMovementTarget(tankUpdate, gameState);
            }

            tankUpdate.TankColor = ConvertColorToHexString(Color.CornflowerBlue);

            return tankUpdate;
        }
Пример #3
0
        public override TankUpdate Update(IGameState gameState)
        {
            TankUpdate tankUpdate = new TankUpdate();
            tankUpdate.TankColor = ConvertColorToHexString(Color.Blue);

            if (gameState.Foes.Any() && gameState.Goals.Any())
            {
                var target = gameState.Foes
                    .Where(foe => 1000 / GetDistanceFromTank(foe) >= 2)
                    .OrderBy(foe => GetDistanceToGoal(foe, gameState.Goals) + GetTimeToGoal(foe, gameState.Goals) + GetDistanceFromTank(foe))
                    .FirstOrDefault();

                if (target != null)
                {
                    tankUpdate.ShotTarget = target.Center;
                    ChangeBulletPower(target);
                    tankUpdate.Bullet = Bullet;
                }

                var x = (gameState.Foes.Max(foe => foe.X) + 9 * gameState.Goals.Last().X) / 10;
                var y = (gameState.Foes.Max(foe => foe.Y) + 9 * gameState.Goals.Last().Y) / 10;
                tankUpdate.MovementTarget = LocationProvider.GetLocation(x, y);
            }

            return tankUpdate;
        }
Пример #4
0
        public override TankUpdate Update(IGameState gameState)
        {
            TankUpdate tankUpdate = new TankUpdate();

            tankUpdate.TankColor = GetRandomColor();

            if (gameState.Foes.Any() && gameState.Goals.Any())
            {
                var target = LocationProvider.GetLocation(375,375);

                if (target != null)
                {
                    tankUpdate.ShotTarget = target;
                    Bullet = new Bullet
                    {
                        Damage = 0,
                        Freeze = 0,
                        SplashRange = 0,
                        GravityDuration = 1,
                        GravityStrength = 0.01
                    };
                    tankUpdate.Bullet = Bullet;
                }
            }

            return tankUpdate;
        }
Пример #5
0
        public override TankUpdate Update(IGameState gameState)
        {
            TankUpdate tankUpdate = new TankUpdate();
            tankUpdate.TankColor = ConvertColorToHexString(Color.Red);

            if (gameState.Foes.Any() && gameState.Goals.Any())
            {
                var target = gameState.Foes
                    .OrderBy(foe => GetDistanceFromTank(foe) + ModifyDistanceByDanger(foe))
                    .FirstOrDefault();

                if (target != null)
                {
                    tankUpdate.ShotTarget = target.Center;
                    ChangeBulletPower(target);
                    tankUpdate.Bullet = Bullet;
                }

                UpdateMovementTarget(tankUpdate, gameState);
            }

            return tankUpdate;
        }
Пример #6
0
        private void DoTankAttack(IGameTank gameTank, TankUpdate tankUpdate, Tank tank)
        {
            gameTank.ShotTarget = tankUpdate.ShotTarget;
            gameTank.Shooting = false;

            if (gameTank.Heat <= 0 && gameTank.ShotTarget != null)
            {
                try
                {
                    var bullet = (Bullet) tankUpdate.Bullet;

                    gameTank.Shooting = true;
                    gameTank.Shots++;
                    gameTank.Bullet = bullet;
                    gameTank.Heat += bullet.GetReloadTime((int)Game.GetDistance(tank.Center.X, tank.Center.Y, tankUpdate.ShotTarget.X, tankUpdate.ShotTarget.Y));

                    List<Monster> foesInRange = _game.GetFoesInRange(tankUpdate.ShotTarget.X,
                        tankUpdate.ShotTarget.Y, bullet.SplashRange);

                    ApplyDamage(gameTank, bullet, foesInRange);
                    ApplyFreeze(gameTank, bullet, foesInRange);
                }
                catch
                {
                    //They made a bad bullet, bad tank!
                }
            }
            else
            {
                gameTank.Heat = Math.Max(gameTank.Heat - 1, 0);
            }
        }
Пример #7
0
        private void MoveTank(IGameTank gameTank, TankUpdate tankUpdate, Tank tank)
        {
            var gameState = _game.GameState;
            if (tankUpdate.MovementTarget != null)
            {
                gameTank.MovementTarget = tankUpdate.MovementTarget;

                var V = new Vector(tankUpdate.MovementTarget.X - tank.X, tankUpdate.MovementTarget.Y - tank.Y);
                var angle = Math.Atan2(V.Y, V.X);
                var speed = Math.Min(tank.Speed, Math.Sqrt(V.X * V.X + V.Y * V.Y));
                var xMovement = speed * Math.Cos(angle);
                var yMovement = speed * Math.Sin(angle);

                if (_game.IsTankInBounds(tank, tank.X + xMovement, tank.Y, gameState))
                {
                    ((Location)tank.Location).X += xMovement;
                }
                else
                {
                    V.X /= 2;
                }

                if (_game.IsTankInBounds(tank, tank.X, tank.Y + yMovement, gameState))
                {
                    ((Location)tank.Location).Y += yMovement;
                }
                else
                {
                    V.Y /= 2;
                }
            }
        }
Пример #8
0
        private void UpdateMovementTarget(TankUpdate tankUpdate, IGameState gameState)
        {
            int maxFoes = GetFoesInRange(_xTarget, _yTarget, gameState);

            for (int i = 0; i < 20; i++)
            {
                var y = _rng.NextDouble() * gameState.Size.Height;
                var x = _rng.NextDouble() * gameState.Size.Width;
                var f = GetFoesInRange(x, y, gameState);
                if (f > maxFoes)
                {
                    maxFoes = f;
                    _xTarget = x;
                    _yTarget = y;
                }
            }

            tankUpdate.MovementTarget = LocationProvider.GetLocation(_xTarget, _yTarget);
        }
Пример #9
0
        private void UpdateMovementTarget(TankUpdate tankUpdate, IGameState gameState)
        {
            double maxFoes = GetFoeCountInRange(_xTarget, _yTarget, gameState, _range) / (_range * Bullet.SplashHeatMultiplier);

            for (int range = 10; range < 200; range += 20)
            {
                for (int i = 0; i < 20; i++)
                {
                    var y = _rng.NextDouble() * gameState.Size.Height;
                    var x = _rng.NextDouble() * gameState.Size.Width;
                    var f = GetFoeCountInRange(x, y, gameState, range);
                    var fd = f / (range * Bullet.SplashHeatMultiplier);
                    if (fd > maxFoes)
                    {
                        maxFoes = f;
                        _xTarget = x;
                        _yTarget = y;
                        _range = range;
                    }
                }
            }

            tankUpdate.MovementTarget = LocationProvider.GetLocation(_xTarget, _yTarget);
        }