Exemple #1
0
        //public static Point GetEnemyVehicleRepulsiveFunction(Vehicle enemyVehicle, double coeff, IList<Vehicle> vehicles, bool isGroundAttak)
        //{
        //    var radius = GetActualShootingDistance(enemyVehicle, isGroundAttak) + MyStrategy.EnemyDangerousRadius;
        //    var centerPoint = MyStrategy.GetVehiclesCenter(vehicles);
        //    var dist = centerPoint.GetDistance(enemyVehicle.X, enemyVehicle.Y);
        //    if (dist > radius) return new Point(0d, 0d);
        //    var x = coeff * (centerPoint.X - enemyVehicle.X) * (1 / dist - 1 / radius) / Math.Pow(dist, 3d);
        //    var y = coeff * (centerPoint.Y - enemyVehicle.Y) * (1 / dist - 1 / radius) / Math.Pow(dist, 3d);
        //    return new Point(x, y);
        //}

        public static Point GetEnemyGroupRepulsiveFunction(GroupContainer groupContainer, double coeff,
                                                           IList <Vehicle> vehicles)
        {
            var enemyRectangle =
                MathHelper.GetJarvisRectangle(groupContainer.Vehicles.Select(v => new Point(v.X, v.Y)).ToList());
            var myCenter = MyStrategy.GetVehiclesCenter(vehicles);

            var enemyCp      = MathHelper.GetNearestRectangleCrossPoint(myCenter, enemyRectangle, groupContainer.Center);
            var myCenterDist = myCenter.GetDistance(groupContainer.Center);
            var radius       = groupContainer.Center.GetDistance(enemyCp) + MyStrategy.EnemyDangerousRadius;

            if (myCenterDist > radius)
            {
                return(new Point(0d, 0d));
            }

            double x, y;

            if (myCenterDist < radius / 2)
            {
                x = coeff * (myCenter.X - groupContainer.Center.X) / myCenterDist;
                y = coeff * (myCenter.Y - groupContainer.Center.Y) / myCenterDist;
            }
            else
            {
                x = 2 * coeff * (myCenter.X - groupContainer.Center.X) * (1 / myCenterDist - 1 / radius);
                y = 2 * coeff * (myCenter.Y - groupContainer.Center.Y) * (1 / myCenterDist - 1 / radius);
            }

            return(new Point(x, y));
        }
Exemple #2
0
 public void AddGroupContainer(GroupContainer gc)
 {
     Vehicles.AddRange(gc.Vehicles);
     Center = new Point(Vehicles.Select(v => v.X).Average(), Vehicles.Select(v => v.Y).Average());
 }