예제 #1
0
파일: MyStrategyP.cs 프로젝트: znsoft/AiCup
 private static double GetSpeed(Unit unit)
 {
     return Math.Sqrt(unit.SpeedX * unit.SpeedX + unit.SpeedY * unit.SpeedY);
 }
예제 #2
0
파일: MyStrategy.cs 프로젝트: znsoft/AiCup
        private double TurretCoeff(Tank self, Unit goal)
        {
            double minDist = 10000;
            for (int i = 0; i < world.Tanks.Length; i++)
                if (!world.Tanks[i].IsTeammate && IsAlive(world.Tanks[i]))
                    if (minDist > self.GetDistanceTo(world.Tanks[i]))
                        minDist = self.GetDistanceTo(world.Tanks[i]);

            if (minDist > self.Width * 6)
            {
                double angle = Math.Abs(NormAngle(goal.Angle - NormAngle(self.GetTurretAngleTo(goal) + self.Angle + self.TurretRelativeAngle)));
                if (angle > Angle[90])
                    angle = Angle[180] - angle;
                return 1 / angle;
            }

            if (world.Tick > 30)
                return 1 / self.GetDistanceTo(goal);

            return 1 / Math.Abs(self.GetTurretAngleTo(goal));
        }
예제 #3
0
파일: MyStrategyP.cs 프로젝트: znsoft/AiCup
 private bool OutOfRange(Unit unit, double error = 1.0)
 {
     double[] X = new double[4];
     double[] Y = new double[4];
     GetCoordinates(unit, X, Y, error);
     return OutOfRange(X[0], Y[0]) && OutOfRange(X[1], Y[1]) || OutOfRange(X[2], Y[2]) && OutOfRange(X[3], Y[3]);
 }
예제 #4
0
파일: MyStrategy.cs 프로젝트: znsoft/AiCup
 private int InUnit(Unit unit, double x, double y, double error = 1.0)
 {
     double[] X = new double[4];
     double[] Y = new double[4];
     GetCoordinates(unit, X, Y, error);
     bool result = InPolygon(x, y, X, Y);
     if (!result)
         return -1;
     double minD = 10000;
     int res = -1;
     for (int i = 0; i < 4; i++)
     {
         double d = DistFromPointToLine(x, y, X[i], Y[i], X[(i + 1) % 4], Y[(i + 1) % 4]) - (i % 2 == 0 ? 0 : 5);
         if (d < minD)
         {
             minD = d;
             res = i;
         }
     }
     return res;
 }
예제 #5
0
파일: MyStrategy.cs 프로젝트: znsoft/AiCup
 private double TankCoeff(Tank self, Unit goal)
 {
     return 1 / /*(Math.Abs(NewAngle(self.GetAngleTo(goal))) * */Math.Pow(self.GetDistanceTo(goal), 0.05);
 }
예제 #6
0
파일: MyStrategy.cs 프로젝트: znsoft/AiCup
 private bool Intersected(Tank self, Unit goal)
 {
     int tmp = 0;
     return Intersected(self, goal, ref tmp);
 }
예제 #7
0
파일: MyStrategy.cs 프로젝트: znsoft/AiCup
        // count - количество препятствующих танков
        private bool Intersected(Tank self, Unit goal, ref int count)
        {
            count = 0;
            bool result = false;
            for (int i = 0; i < world.Tanks.Length; i++)
            {
                if (self.Id != world.Tanks[i].Id && world.Tanks[i].Id != goal.Id && Intersected(world.Tanks[i], self, goal, 1.2))
                {
                    result = true;
                    count++;
                }
            }

            for (int i = 0; i < world.Obstacles.Length; i++)
                if (goal.Id != world.Obstacles[i].Id && Intersected(world.Obstacles[i], self, goal, 1.05))
                    result = true;
            for (int i = 0; i < world.Bonuses.Length; i++)
                if (goal.Id != world.Bonuses[i].Id && Intersected(world.Bonuses[i], self, goal, 1.3))
                    result = true;
            return result;
        }
예제 #8
0
파일: MyStrategy.cs 프로젝트: znsoft/AiCup
        private void GetCoordinates(Unit u, double[] X, double[] Y, double error = 1.0)
        {
            double x = u.X;
            double y = u.Y;
            double w = error * u.Width / 2;
            double h = error * u.Height / 2;
            double angle = u.Angle;

            X[0] = w;
            Y[0] = h;
            X[1] = w;
            Y[1] = -h;
            X[2] = -w;
            Y[2] = -h;
            X[3] = -w;
            Y[3] = h;

            for (int i = 0; i < 4; i++)
            {
                double nx = RotatedX(X[i], Y[i], angle) + x;
                Y[i] = RotatedY(X[i], Y[i], angle) + y;
                X[i] = nx;
            }
        }
예제 #9
0
파일: MyStrategy.cs 프로젝트: znsoft/AiCup
 private bool Intersected(Unit unit, Tank self, Unit goal, double error = 1.0)
 {
     double[] X = new double[4];
     double[] Y = new double[4];
     GetCoordinates(unit, X, Y, error);
     return Intersected(goal.X, goal.Y, self.X, self.Y, X, Y, error);
 }
예제 #10
0
 /// <summary>
 /// Returns the relative angle in range of -PI to PI both inclusive.
 /// </summary>
 /// <param name="unit">Unit to calculate turret relative angle to.</param>
 /// <returns>Angle to the center of specified unit relative to this tank turret's angle.</returns>
 public double GetTurretAngleTo(Unit unit)
 {
     return GetTurretAngleTo(unit.X, unit.Y);
 }
예제 #11
0
파일: MyStrategy.cs 프로젝트: znsoft/AiCup
        private bool FFF(Tank self, Unit goal, Tank en)
        {
            for (int i = 0; i < world.Tanks.Length; i++)
            {
                if (self.Id != world.Tanks[i].Id && world.Tanks[i].Id != en.Id && Intersected(world.Tanks[i], self, goal, 1.2) && self.GetDistanceTo(world.Tanks[i]) < self.GetDistanceTo(en))
                {
                    return true;
                }
            }

            // for (int i = 0; i < world.Obstacles.Length; i++) if (goal.Id != world.Obstacles[i].Id && Intersected(world.Obstacles[i], self, goal)) return true;
            for (int i = 0; i < world.Bonuses.Length; i++)
                if (goal.Id != world.Bonuses[i].Id && Intersected(world.Bonuses[i], self, goal, 1.3) && self.GetDistanceTo(world.Bonuses[i]) < self.GetDistanceTo(en))
                    return true;
            return false;
        }
예제 #12
0
 /// <summary>
 /// Returns the distance to the unit's center.
 /// </summary>
 /// <param name="unit">Unit to calculate distance to.</param>
 /// <returns>Distance to the center of specified unit from the center of this unit.</returns>
 public double GetDistanceTo(Unit unit)
 {
     return GetDistanceTo(unit.x, unit.y);
 }
예제 #13
0
 /// <summary>
 /// Returns the relative angle in range of -PI to PI both inclusive.
 /// </summary>
 /// <param name="unit">Unit to calculate relative angle to.</param>
 /// <returns>Angle to the center of specified unit relative to this unit's angle.</returns>
 public double GetAngleTo(Unit unit)
 {
     return GetAngleTo(unit.x, unit.y);
 }
예제 #14
0
 public static double MovementSpeed(Unit unit)
 {
     return Mathematics.Pythagor(unit.SpeedX, unit.SpeedY);
 }
예제 #15
0
 //public List<TankCollision> Collision(Point A, double angle, ShellType shellType)
 //{
 //    Collision tmpCollision;
 //    List<TankCollision> tmpResult = new List<TankCollision>();
 //    for (int tick = 0; tick < Settings.PredictionLength; ++tick)
 //        for (int i = 0; i < 4; ++i)
 //            if ((tmpCollision = SurfacePrediction[tick][i].Collision(A, angle, shellType)) != null)
 //            {
 //                tmpResult.Add(new TankCollision(tmpCollision, i == 0 ? Properties.ArmorProperties[ArmorType.Front] : (i == 3 ? Properties.ArmorProperties[ArmorType.Rear] : Properties.ArmorProperties[ArmorType.Side])));
 //                break;
 //            }
 //    return tmpResult;
 //}
 public static double MovementAngle(Unit unit)
 {
     return Mathematics.VectorAngle(unit.SpeedX, unit.SpeedY);
 }
예제 #16
0
파일: Ray.cs 프로젝트: sigod/russianaicup
 public bool IsCollide(Unit with)
 {
     return this.IsCollide(new Location(with.X, with.Y, with.Angle, with.Width, with.Height));
 }