Ejemplo n.º 1
0
        private void CheckForNukeComing()
        {
            var oppPlayer = Universe.World.GetOpponentPlayer();

            if (oppPlayer.NextNuclearStrikeTickIndex > 0)
            {
                var       affectedSquadsList = new List <Squad>();
                var       nukeCenter         = new AbsolutePosition(oppPlayer.NextNuclearStrikeX, oppPlayer.NextNuclearStrikeY);
                var       nukeRadius         = Universe.Game.TacticalNuclearStrikeRadius;
                const int duration           = 31;
                var       squaredNukeRadius  = nukeRadius * nukeRadius;

                foreach (var squad in SquadList.Where(s => !s.IsWaitingForScaling &&
                                                      s.IsEnabled &&
                                                      !s.IsEmpty &&
                                                      !s.IsScout))
                {
                    foreach (var unit in squad.Units)
                    {
                        if (unit.GetSquaredDistanceTo(nukeCenter.X, nukeCenter.Y) < squaredNukeRadius)
                        {
                            affectedSquadsList.Add(squad);
                        }
                    }
                }

                var chosenSquad = affectedSquadsList.Distinct().ToList().FirstOrDefault();
                chosenSquad?.DoScaleJerk(ImmediateActionList, DeferredActionList, 10, nukeCenter, duration, Universe.World.TickIndex + duration);
            }
        }
Ejemplo n.º 2
0
 public ActionScaleSelectedSquadToPosition(Squad squad, double factor, AbsolutePosition position, int duration)
 {
     this.squad    = squad;
     this.factor   = factor;
     this.position = position;
     this.duration = duration;
 }
Ejemplo n.º 3
0
        public bool Execute(Universe universe)
        {
            var selectedUnits = universe.GetSelectedUnits();

            if (!selectedUnits.Any())
            {
                universe.Print("Can avoid the movement. Selected unit is absent or dead.");
                return(false);
            }

            var centralUnit     = selectedUnits.GetCentralUnit();
            var selectionCenter = new AbsolutePosition(centralUnit.X, centralUnit.Y);

            if (selectionCenter.GetDistanceToPoint(position.X, position.Y) < 5)
            {
                universe.Print("Can avoid the movement.");
                return(false);
            }

            //var moveOrderList = MyStrategy.MoveOrder;

            SquadCalculator.MoveOrders.Update(selectedUnits, centralUnit, position);
            //if (centralUnit.GetDistanceTo(position) > 200)
            //    universe.Print("Wrong move order");

            universe.Move.Action   = ActionType.Move;
            universe.Move.X        = position.X - selectionCenter.X;
            universe.Move.Y        = position.Y - selectionCenter.Y;
            universe.Move.MaxSpeed = speed;
            //universe.Print($"Action {this} is started.");
            return(true);
        }
Ejemplo n.º 4
0
        public static Range2 GetRange(this AbsolutePosition position, double radius)
        {
            var XMin = position.X - radius;
            var XMAx = position.X - radius;
            var YMin = position.Y - radius;
            var YMax = position.Y - radius;

            return(new Range2(XMin, XMAx, YMin, YMax));
        }
Ejemplo n.º 5
0
        public static Range2 GetRange(this AbsolutePosition position, double width, double height)
        {
            var XMin = position.X - width / 2;
            var XMAx = position.X - width / 2;
            var YMin = position.Y - height / 2;
            var YMax = position.Y - height / 2;

            return(new Range2(XMin, XMAx, YMin, YMax));
        }
Ejemplo n.º 6
0
 public void Update(List<Vehicle> selectedUnits, Vehicle centralUnit, AbsolutePosition position)
 {
     foreach (var unit in selectedUnits)
     foreach (var moveOrder in new SortedList<long, AbsolutePosition>(OrderList))
     {
         if (moveOrder.Key == unit.Id)
             OrderList.Remove(moveOrder.Key);
     }
     OrderList.Add(centralUnit.Id, position);
 }
Ejemplo n.º 7
0
        //public double AirEnergy => (AirForce + AirDefence) / DispersionSquared;
        //public double AirEnergyRelative => AirEnergy / StartAirEnergy;
        //public double GroundEnergyRelative => GroundEnergy / StartGroundEnergy;
        //public double GroundEnergy => (GroundForce + GroundDefence) / DispersionSquared;

        //public double Energy => GroundEnergy + AirEnergy;

        #endregion

        #region Actions

        internal void DoMove(Queue <IMoveAction> actions, AbsolutePosition position)
        {
            if (NukeMarkerCounter == 0)
            {
                actions.ActionSelectSquad(Id);
                actions.ActionMoveSelectionToPosition(position);
            }
            else
            {
                MyStrategy.Universe.Print($"Squad {(Squads)Id} is locked due to Nuke marker.");
            }
            UpdateLastCallTime(MyStrategy.Universe.World.TickIndex);
        }
Ejemplo n.º 8
0
        private BonusMap GetAeroDangerMap(List <Vehicle> enemyUnits, AbsolutePosition squadCenter, MapType mapType)
        {
            const double affectedRange    = 500;
            var          enemyUnitsForMap = enemyUnits.Where(
                u => (u.X - squadCenter.X) < affectedRange &&
                (u.Y - squadCenter.Y) < affectedRange
                ).ToList();

            var map = new BonusMap(mapType);

            foreach (var unit in enemyUnitsForMap)
            {
                map.AddUnitCalculation(unit, unit.AerialAttackRange * 1, unit.AerialDamage, unit.AerialAttackRange * 2.5);
            }

            return(map);
        }
Ejemplo n.º 9
0
        private BonusMap GetScoutBonusMap(List <Vehicle> enemyUnits, AbsolutePosition squadCenter, double scoutVisionRange, MapType mapType)
        {
            const double affectedRange = 1200;
            var          unitsForMap   = enemyUnits.Where(
                u => (u.X - squadCenter.X) < affectedRange &&
                (u.Y - squadCenter.Y) < affectedRange &&
                u.Type != VehicleType.Arrv
                ).ToList();

            var map = new BonusMap(mapType);

            foreach (var unit in unitsForMap)
            {
                map.AddUnitCalculation(unit, scoutVisionRange, unit.AerialDamage + unit.GroundDamage, 800);
            }
            return(map);
        }
Ejemplo n.º 10
0
        private void CalculateProperties()
        {
            SquaredDispersionList = Units.GetUnitsSquaredDispersionList();
            CentralUnit           = GetSquadCentralUnit(); // order metters. Depends on the SquaredDispersionList

            if (CentralUnit == null)
            {
                SquadCenter = new AbsolutePosition();
            }
            else
            {
                SquadCenter = new AbsolutePosition(CentralUnit.X, CentralUnit.Y);
            }

            CruisingSpeed      = CalculateCruisingSpeed();
            DispersionSquared  = GetUnitsSquaredDispersionValue(); // order metters. Depends on the SquaredDispersionList
            DispersionRelative = DispersionSquared / StartDispersionSquared;
        }
Ejemplo n.º 11
0
        //public double FairValue { get; internal set; } = 0;


        internal double GetNukeDamage(AbsolutePosition targetPoint, double range)
        {
            double damage = 0;

            //var visabilityKoeff = 0.8;

            foreach (var unit in Units)
            {
                var distanceFromNuceCenter = unit.GetDistanceTo(targetPoint.X, targetPoint.Y);
                var damageKoeff            = (range - distanceFromNuceCenter) / range;
                var healthKoeff            = 1 / unit.GetUnitHealthIndex();
                var unitForce = unit.AerialDamage + unit.AerialDefence + unit.GroundDamage + unit.GroundDefence;

                //damage += unitForce * damageKoeff * healthKoeff;
                damage += unitForce * damageKoeff;
            }
            return(damage);
        }
Ejemplo n.º 12
0
        public static void AddUnitCalculation(BonusMap map, AbsolutePosition unitPosition, double maxValueDistance, double maxValue, double zeroValueDistance)
        {
            if (maxValueDistance > zeroValueDistance)
            {
                MyStrategy.Universe.Print("Warning! Zero map distance greater then Max value distance!");
                //throw new Exception("Wrong distance limits.");
                zeroValueDistance = maxValueDistance;
            }

            var maxValueDistanceSquared  = maxValueDistance * maxValueDistance;
            var zeroValueDistanceSquared = zeroValueDistance * zeroValueDistance;

            for (int i = 0; i < BonusMapCalculator.MapPointsAmount; i++)
            {
                for (int j = 0; j < BonusMapCalculator.MapPointsAmount; j++)
                {
                    var distanceSquared = unitPosition.GetSquaredDistanceToPoint(i * BonusMapCalculator.SizeWorldMapKoeff, j * BonusMapCalculator.SizeWorldMapKoeff);

                    if (distanceSquared <= maxValueDistanceSquared)
                    {
                        if (map.MapType == MapType.Flat)
                        {
                            map.Table[i, j] = Math.Max(maxValue, map.Table[i, j]);
                        }
                        else
                        {
                            map.Table[i, j] += maxValue;
                        }
                    }

                    if (distanceSquared > maxValueDistanceSquared && distanceSquared < zeroValueDistanceSquared)
                    {
                        if (map.MapType == MapType.Flat)
                        {
                            map.Table[i, j] = Math.Max(maxValue - ((distanceSquared - maxValueDistanceSquared) / zeroValueDistanceSquared), map.Table[i, j]);
                        }
                        else
                        {
                            map.Table[i, j] += maxValue - ((distanceSquared - maxValueDistanceSquared) / zeroValueDistanceSquared);
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public static double GetPotentialNuclearWin(this Vehicle targetUnit, Universe universe, double range)
        {
            var myGuys       = new List <Vehicle>();
            var enemyGuys    = new List <Vehicle>();
            var squaredRange = range * range;

            var targetPoint = new AbsolutePosition(targetUnit.X, targetUnit.Y);

            //var predictedState = MyStrategy.Predictor.GetStateOnTick(universe.World.TickIndex + 30);
            //var enemyUnits = predictedState.OppUnits.Where(u => u.Type != VehicleType.Arrv);
            //var myUnits = predictedState.MyUnits.Where(u => u.Type != VehicleType.Arrv);

            var enemyUnits = universe.OppUnits.Where(u => u.Type != VehicleType.Arrv);
            var myUnits    = universe.MyUnits.Where(u => u.Type != VehicleType.Arrv);

            foreach (var enemyGuy in enemyUnits)
            {
                var distanceSquaredFromNuceCenter = targetUnit.GetSquaredDistanceTo(enemyGuy);
                if (distanceSquaredFromNuceCenter < squaredRange)
                {
                    enemyGuys.Add(enemyGuy);
                }
            }

            foreach (var myGuy in myUnits)
            {
                var distanceSquaredFromNuceCenter = targetUnit.GetSquaredDistanceTo(myGuy);
                if (distanceSquaredFromNuceCenter < squaredRange && targetUnit != myGuy)
                {
                    myGuys.Add(myGuy);
                }
            }

            var totalEnergyWin = new Squad(enemyGuys).GetNukeDamage(targetPoint, range) - new Squad(myGuys).GetNukeDamage(targetPoint, range);

            return(totalEnergyWin);
        }
Ejemplo n.º 14
0
 public static void ActionScaleSquadToPosition(this Queue <IMoveAction> actions, Squad squad, double factor, AbsolutePosition position, int duration)
 {
     actions.ActionSelectSquad(squad.Id);
     actions.Enqueue(new ActionScaleSelectedSquadToPosition(squad, factor, position, duration));
     squad.IsWaitingForScaling = true;
     squad.UpdateLastCallTime(MyStrategy.Universe.World.TickIndex);
 }
Ejemplo n.º 15
0
 public static void ActionRotateSelection(this Queue <IMoveAction> moveActions, AbsolutePosition center, double angleChange) =>
 moveActions.Enqueue(new ActionRotateSelection(center, angleChange));
Ejemplo n.º 16
0
 public static bool IsInRange2(this AbsolutePosition position, Range2 range) =>
 Geom.Between(range.XMin, range.XMax, position.X) && Geom.Between(range.YMin, range.YMax, position.Y);
Ejemplo n.º 17
0
        internal void DoScaleJerk(Queue <IMoveAction> actions, List <DeferredAction> deferredActionsList, double factor, AbsolutePosition nukeCenter, int duration, int deferredTickIndex)
        {
            actions.ActionScaleSquadToPosition(this, factor, nukeCenter, duration);

            var deferredActions = new Queue <IMoveAction>();

            deferredActions.ActionScaleSquadToPosition(this, 0.1, nukeCenter, (int)1.5 * duration);

            // TODO if queue is log, there is not time for movement, planned combining time is behind.
            foreach (var action in deferredActions)
            {
                //TODO impossible to set exact required time for deferred action
                deferredActionsList.Add(new DeferredAction(action, deferredTickIndex));
            }
            UpdateLastCallTime(MyStrategy.Universe.World.TickIndex);
        }
Ejemplo n.º 18
0
 public ActionRequestNuclearStrike(Vehicle scout, Vehicle target)
 {
     this.scout       = scout;
     this.target      = target;
     this.targetPoint = new AbsolutePosition(target.X, target.Y);
 }
Ejemplo n.º 19
0
 public ActionRotateSelection(AbsolutePosition center, double angleChange)
 {
     this.center      = center;
     this.angleChange = angleChange;
 }
Ejemplo n.º 20
0
 public ActionMoveSelectionToPosition(AbsolutePosition position, double speed = 1)
 {
     this.position = position;
     this.speed    = speed;
 }
Ejemplo n.º 21
0
        private BonusMap GetGroundCollisionMap(List <Vehicle> allUnits, List <long> squadIds, AbsolutePosition squadCenter, MapType mapType)
        {
            const double affectedRange = 300;
            var          unitsForMap   = allUnits.Where(
                u => !u.IsAerial &&
                !squadIds.Contains(u.Id) &&
                (u.X - squadCenter.X) < affectedRange &&
                (u.Y - squadCenter.Y) < affectedRange
                ).ToList();
            var map = new BonusMap(mapType);

            foreach (var unit in unitsForMap)
            {
                map.AddUnitCalculation(unit, 10, 1, 30);
            }

            return(map);
        }
Ejemplo n.º 22
0
 public static void ActionMoveSelectionToPosition(this Queue <IMoveAction> moveActions, AbsolutePosition position, double speed) =>
 moveActions.Enqueue(new ActionMoveSelectionToPosition(position, speed));
Ejemplo n.º 23
0
 public double GetSquaredDistanceToPoint(AbsolutePosition position) => GetSquaredDistanceToPoint(position.X, position.Y);
Ejemplo n.º 24
0
        public static bool DoISeeThisPoint(this Vehicle myUnit, AbsolutePosition point)
        {
            var squaredRange = myUnit.SquaredVisionRange * 0.6;

            return(myUnit.GetSquaredDistanceTo(point.X, point.Y) < squaredRange);
        }