Пример #1
0
        public World(int tick, double width, double height, Player[] players, Obstacle[] obstacles, Tank[] tanks, Shell[] shells, Bonus[] bonuses)
        {
            this.tick = tick;
            this.width = width;
            this.height = height;

            this.players = new Player[players.Length];
            Array.Copy(players, this.players, players.Length);

            this.obstacles = new Obstacle[obstacles.Length];
            Array.Copy(obstacles, this.obstacles, obstacles.Length);

            this.tanks = new Tank[tanks.Length];
            Array.Copy(tanks, this.tanks, tanks.Length);

            this.shells = new Shell[shells.Length];
            Array.Copy(shells, this.shells, shells.Length);

            this.bonuses = new Bonus[bonuses.Length];
            Array.Copy(bonuses, this.bonuses, bonuses.Length);
        }
Пример #2
0
 private bool IsNeed(Tank self, Bonus bonus)
 {
     return (self.CrewHealth < self.CrewMaxHealth && bonus.Type == BonusType.Medikit) ||
            (self.HullDurability < self.HullMaxDurability && bonus.Type == BonusType.RepairKit) ||
            (bonus.Type == BonusType.AmmoCrate && self.PremiumShellCount < 3);
 }
Пример #3
0
        private Bonus[] ReadBonuses()
        {
            int bonusCount = ReadInt();
            if (bonusCount < 0)
            {
                return null;
            }

            Bonus[] bonuses = new Bonus[bonusCount];

            for (int bonusIndex = 0; bonusIndex < bonusCount; ++bonusIndex)
            {
                if (ReadBoolean())
                {
                    bonuses[bonusIndex] = new Bonus(ReadLong(), ReadDouble(), ReadDouble(), ReadDouble(), ReadDouble(), (BonusType)ReadEnum());
                }
            }

            return bonuses;
        }
Пример #4
0
        //public static void Set()
        //{
        //    Time = Stopwatch.ElapsedTicks;
        //}
        //public static void Lap(string comment)
        //{
        //    Console.WriteLine(comment + ": " + (Stopwatch.ElapsedTicks - Time));
        //    Set();
        //}
        public void Move(Tank self, World world, Move move)
        {
            Self = self;
            SelfLocation = new Point(Self.X, Self.Y);
            World = world;

            AnglesRegular.Clear();
            AnglesPremium.Clear();

            //for (int i = 0; i < _lol; ++i)
            //{
            //    i += 1;
            //    i -= 1;
            //}

            //Point tmpIntersection;
            //var t00 = Mathematics.DoSegmentsIntersect(new Point(10, 10), new Point(110, 15), new Point(60, 50), new Point(60, 0), out tmpIntersection);

            //return;

            //var t00 = Mathematics.Newton(x => x * x, x => 2 * x, 2, 0.00000001); // 1.41421356237
            //var t01 = Mathematics.Newton(x => x * x * x, x => 3 * x * x, 2, 0.0000001); // 1.25992104989

            //var tmpShellType = ShellType.Regular;
            //double tmpDistance = 0;

            //foreach (Tank tmpTank in world.Tanks)
            //    if (tmpTank.PlayerName == "QuickStartGuy")
            //    {
            //        tmpDistance = Mathematics.Distance(new Point(Self.X, Self.Y), new Point(tmpTank.X, tmpTank.Y)) - 100;
            //        break;
            //    }

            //var t02 = Mathematics.Newton(
            //    t => (MyStrategy.ShellProperties[tmpShellType].InitialSpeed * (Math.Exp(MyStrategy.ShellProperties[tmpShellType].SpeedPowerRatio * t) - 1)) / MyStrategy.ShellProperties[tmpShellType].SpeedPowerRatio, // integral of speed
            //    t => MyStrategy.ShellProperties[tmpShellType].InitialSpeed * Math.Exp(MyStrategy.ShellProperties[tmpShellType].SpeedPowerRatio * t), // speed
            //    tmpDistance, Settings.TickApproximationEpsilon);

            //return;

            //Set();

            if (Tanks == null)
            {
                Tanks = new Dictionary<long, Tank>();

                foreach (Tank tmpTank in world.Tanks)
                    Tanks.Add(tmpTank.Id, tmpTank);

                TankPlus = new Dictionary<long, TankPlus>();

                foreach (Tank tmpTank in world.Tanks)
                    TankPlus.Add(tmpTank.Id, new TankPlus(tmpTank.Id));

                //Bonuses = new Dictionary<long, Bonus>();
                //BonusPlus = new Dictionary<long, BonusPlus>();
            }
            else
            {
                foreach (Tank tmpTank in world.Tanks)
                    Tanks[tmpTank.Id] = tmpTank;

                //List<long> tmpOutdatedBonuses = new List<long>();

                //foreach (BonusPlus tmpBonusPlus in BonusPlus.Values)
                //    if (tmpBonusPlus.DeathTick == World.Tick)
                //        tmpOutdatedBonuses.Add(tmpBonusPlus.Id);

                //foreach (long tmpBonusId in tmpOutdatedBonuses)
                //{
                //    Bonuses.Remove(tmpBonusId);
                //    BonusPlus.Remove(tmpBonusId);
                //}

                //foreach (Bonus tmpBonus in world.Bonuses)
                //    if (!Bonuses.ContainsKey(tmpBonus.Id))
                //    {
                //        Bonuses.Add(tmpBonus.Id, tmpBonus);
                //        BonusPlus.Add(tmpBonus.Id, new BonusPlus(tmpBonus.Id, World.Tick + Settings.BonusLifeTime));
                //    }
            }

            foreach (TankPlus tmpTankPlus in TankPlus.Values)
                tmpTankPlus.Update();

            if (!TankPlus[Self.Id].IsAlive)
                return;

            // SHOOTING -------------------------------------------------------------------------------------------------------------

            AnglesRegular.Sort((Comparison<KeyValuePair<double, double>>)((x, y) => y.Value.CompareTo(x.Value)));
            AnglesPremium.Sort((Comparison<KeyValuePair<double, double>>)((x, y) => y.Value.CompareTo(x.Value)));

            double tmpAngle = Self.Angle + Self.TurretRelativeAngle, bestAngle = tmpAngle;

            if (AnglesRegular.Count > 0 && AnglesRegular[0].Value > 0)
            {
                bestAngle = AnglesRegular[0].Key;

                if (Math.Abs(Mathematics.AngleDifference(tmpAngle, AnglesRegular[0].Key)) < 0.017453292519943) // 1 degree
                    move.FireType = FireType.Regular;
            }

            if (Self.PremiumShellCount > 0 && AnglesPremium.Count > 0 && (AnglesRegular.Count == 0 || AnglesPremium[0].Value > AnglesRegular[0].Value))
            {
                bestAngle = AnglesPremium[0].Key;

                if (Math.Abs(Mathematics.AngleDifference(tmpAngle, AnglesPremium[0].Key)) < 0.017453292519943)
                    move.FireType = FireType.Premium;
            }

            if (bestAngle != tmpAngle)
            {
                double tmpTurnAngle = Mathematics.AngleDifference(tmpAngle, bestAngle);

                move.TurretTurn = tmpTurnAngle;
                //move.LeftTrackPower = tmpTurnAngle > 0 ? Self.EngineRearPowerFactor : -1;
                //move.RightTrackPower = tmpTurnAngle < 0 ? Self.EngineRearPowerFactor : -1;
            }

            // DRIVING -------------------------------------------------------------------------------------------------------------

            double bestBonusDistance = 10000, tmpDistance;
            Point bestBonusLocation = new Point(), tmpBonusLocation;
            bool haveTarget = false;

            foreach (Bonus tmpBonus in World.Bonuses)
            {
                tmpBonusLocation = new Point(tmpBonus.X, tmpBonus.Y);
                tmpDistance = Mathematics.Distance(SelfLocation, tmpBonusLocation);

                if ((_currentBonus != null && tmpBonus.Id == _currentBonus.Id) || tmpDistance < bestBonusDistance)
                {
                    haveTarget = true;
                    _currentBonus = tmpBonus;
                    bestBonusDistance = tmpDistance;
                    bestBonusLocation = tmpBonusLocation;
                }
            }

            if (!haveTarget)
            {
                _currentBonus = null;
                return;
            }

            //double movementAngle = TankPlus[Self.Id].AnglePrediction[0];
            double turnAngle = Mathematics.AngleDifference(Self.Angle, Mathematics.SegmentAngle(SelfLocation, bestBonusLocation));

            if (Math.Abs(turnAngle) < Mathematics.SixthPI)
            {
                move.LeftTrackPower = 1;
                move.RightTrackPower = 1;
            }
            else
            {
                move.TurretTurn = turnAngle;
                move.LeftTrackPower = turnAngle > 0 ? 0.75 : -1;
                move.RightTrackPower = turnAngle < 0 ? 0.75 : -1;
            }

            /*double turnRatio = (Math.PI * Math.PI - Math.Abs(turnAngle * turnAngle)) / (Math.PI * Math.PI);

            if (Math.Abs(turnAngle) < Mathematics.HalfPI)
            {
                turnRatio /= 2;

                if (Math.Abs(turnAngle) < Mathematics.ThirdPI)
                {
                    turnRatio /= 2;

                    if (Math.Abs(turnAngle) < Mathematics.SixthPI)
                    {
                        turnRatio /= 2;
                    }
                }
            }

            move.LeftTrackPower = turnAngle > 0 ? 1 - 0.25 * turnRatio : 1 - 2 * turnRatio;
            move.RightTrackPower = turnAngle < 0 ? 1 - 0.25 * turnRatio : 1 - 2 * turnRatio;*/

            //double tmpAngle = Mathematics.AddAnglesAbsolute(Self.Angle, Self.TurretRelativeAngle);
            //Point tmpLocation = new Point(Self.X, Self.Y);
            //List<KeyValuePair<double, double>> tmpAnglesRegular = new List<KeyValuePair<double, double>>();
            //List<KeyValuePair<double, double>> tmpAnglesPremium = new List<KeyValuePair<double, double>>();

            //for (int i = -Settings.PredictionAngleCount; i < Settings.PredictionAngleCount; ++i)
            //{
            //    double tmpTestAngle = Mathematics.AddAnglesAbsolute(tmpAngle, Settings.PredictionAngleStep * i);
            //    tmpAnglesRegular.Add(new KeyValuePair<double, double>(tmpTestAngle, CalculateValue(tmpLocation, tmpTestAngle, ShellType.Regular)));
            //    //tmpAnglesPremium.Add(new KeyValuePair<double, double>(tmpTestAngle, CalculateValue(tmpLocation, tmpTestAngle, ShellType.Premium)));
            //}

            //tmpAnglesRegular.Sort((Comparison<KeyValuePair<double, double>>)((x, y) => y.Value.CompareTo(x.Value)));
            ////tmpAnglesPremium.Sort((Comparison<KeyValuePair<double, double>>)((x, y) => y.Value.CompareTo(x.Value)));

            //if (tmpAnglesRegular[0].Key == tmpAngle && tmpAnglesRegular[0].Value > Settings.RegularLimit)
            //    move.FireType = FireType.Regular;

            ////if (Self.PremiumShellCount > 0 && tmpAnglesPremium[0].Key == tmpAngle && tmpAnglesPremium[0].Value > Settings.RegularLimit)
            ////    move.FireType = FireType.Premium;

            //if (move.FireType == null && tmpAnglesRegular[0].Value > 0)
            //{
            //    double tmpTurnAngle = tmpAnglesRegular[0].Key;

            //    //if (tmpAnglesRegular[0].Value > tmpAnglesPremium[0].Value)
            //    //    tmpTurnAngle = tmpAnglesRegular[0].Key;
            //    //else
            //    //    tmpTurnAngle = tmpAnglesPremium[0].Key;

            //    move.TurretTurn = Mathematics.AddAnglesAbsolute(tmpTurnAngle, -tmpAngle);
            //    move.LeftTrackPower = move.TurretTurn > 0 ? Self.EngineRearPowerFactor : -1;
            //    move.RightTrackPower = move.TurretTurn < 0 ? Self.EngineRearPowerFactor : -1;
            //}

            ////Lap("A");
            ////Console.ReadLine();
        }