Exemple #1
0
        // Compute logic here. This method is called for each game round.
        public void Play()
        {
            var myDrones = _teams[_myTeamId].Drones;

            #region Zones loop
            foreach (var zone in _zones)
            {
                zone.MaxDrones = 0;
                zone.MyDrones  = 0;
                zone.MaxTreat  = 0;
                zone.TargetDrone.Clear();
                foreach (var team in _teams)
                {
                    int count = team.Drones.Count(a => ProximityDetection(zone.Center, a.Position));
                    if (count > 0)
                    {
                        if (team.TeamId == _myTeamId)
                        {
                            zone.MyDrones = count;
                        }
                        else
                        {
                            zone.MaxDrones = count > zone.MaxDrones ? count : zone.MaxDrones;
                        }
                    }

                    count = team.Drones.Count(a => TreatDetection(zone.Center, a.Position));
                    if (count > 0)
                    {
                        if (team.TeamId != _myTeamId)
                        {
                            zone.MaxTreat = count > zone.MaxTreat ? count : zone.MaxTreat;
                        }
                    }
                }
                zone.TargetDrone = new List <TargetDrone>(myDrones.Count());
                zone.TargetDrone.AddRange(myDrones.Select(myDrone => new TargetDrone
                {
                    Distance = GetDistance(myDrone.Position.X, myDrone.Position.Y, zone.Center.X, zone.Center.Y),
                    Drone    = myDrone
                }));
                zone.BestDistance = zone.TargetDrone.OrderBy(o => o.Distance).Select(a => a.Distance).First();

                if (zone.OwnerId == _myTeamId && zone.MaxTreat > 0)
                {
                    zone.ZoneClass = 0;
                }
                else if (zone.OwnerId != _myTeamId && zone.MaxDrones == 0)
                {
                    zone.ZoneClass = 1;
                }
                else if (zone.OwnerId != _myTeamId && zone.MaxTreat < 2)
                {
                    zone.ZoneClass = 2;
                }
                else if (zone.OwnerId != _myTeamId && zone.MaxTreat > 1)
                {
                    zone.ZoneClass = 3;
                }
                else if (zone.OwnerId == _myTeamId && zone.MaxTreat == 0)
                {
                    zone.ZoneClass = 4;
                }
            }
            #endregion

            #region drones loop
            foreach (var drone in myDrones)
            {
                drone.TargetZones.Clear();
                drone.Target = null;
                foreach (var zone in _zones)
                {
                    TargetZone tZ = new TargetZone {
                        Zone = zone, Distance = GetDistance(drone.Position.X, drone.Position.Y, zone.Center.X, zone.Center.Y)
                    };
                    drone.TargetZones.Add(tZ);
                }

                if (drone.TargetZones.Count(z => z.Distance < 100 && z.Zone.MaxTreat > 0 && z.Zone.OwnerId == _myTeamId) > 0)
                {
                    drone.DroneClass = 0;
                }
                else if (drone.TargetZones.Count(z => z.Distance < 300 && z.Zone.OwnerId != _myTeamId) > 0)
                {
                    drone.DroneClass = 1;
                }
                else
                {
                    drone.DroneClass = 2;
                }
            }

            #endregion

            GetTargetZone(_zones, myDrones);

            foreach (Drone drone in myDrones)
            {
                string cords;
                if (drone.Target == null)
                {
                    TargetZone tz = drone.TargetZones.OrderBy(o => o.Distance).FirstOrDefault(f => f.Zone.OwnerId == _myTeamId);
                    if (tz == null)
                    {
                        Point wheretogo = GetGravityPoint(_zones);
                        cords = (wheretogo.X) + " " + (wheretogo.Y);
                    }
                    else
                    {
                        cords = (tz.Zone.Center.X) + " " + (tz.Zone.Center.Y);
                    }
                }
                else
                {
                    cords = (drone.Target.Center.X) + " " + (drone.Target.Center.Y);
                }
                Console.WriteLine(cords);
            }

            //debugger part
            //foreach (var zone in _zones.OrderBy(z => z.ZoneClass).ThenBy(z => z.BestDistance))
            //{

            //		Console.Error.WriteLine("zona " + zone.ZoneId + " klasa " + zone.ZoneClass);


            //}
            //Console.Error.WriteLine("===========================");
            //foreach (var drone in myDrones)
            //{
            //	Console.Error.WriteLine("dron " + drone.DroneClass);
            //}
        }
        // Compute logic here. This method is called for each game round.
        public void Play()
        {
            var myDrones = _teams[_myTeamId].Drones;

            #region Zones loop
            foreach (var zone in _zones)
            {
                zone.MaxDrones = 0;
                zone.MyDrones = 0;
                zone.MaxTreat = 0;
                zone.TargetDrone.Clear();
                foreach (var team in _teams)
                {
                    int count = team.Drones.Count(a => ProximityDetection(zone.Center, a.Position));
                    if (count > 0)
                    {
                        if (team.TeamId == _myTeamId)
                        {
                            zone.MyDrones = count;
                        }
                        else
                        {
                            zone.MaxDrones = count > zone.MaxDrones ? count : zone.MaxDrones;
                        }
                    }

                    count = team.Drones.Count(a => TreatDetection(zone.Center, a.Position));
                    if (count > 0)
                    {
                        if (team.TeamId != _myTeamId)
                        {
                            zone.MaxTreat = count > zone.MaxTreat ? count : zone.MaxTreat;
                        }
                    }

                }
                zone.TargetDrone = new List<TargetDrone>(myDrones.Count());
                zone.TargetDrone.AddRange(myDrones.Select(myDrone => new TargetDrone
                {
                    Distance = GetDistance(myDrone.Position.X, myDrone.Position.Y, zone.Center.X, zone.Center.Y),
                    Drone = myDrone
                }));
                zone.BestDistance = zone.TargetDrone.OrderBy(o => o.Distance).Select(a => a.Distance).First();

                if (zone.OwnerId == _myTeamId && zone.MaxTreat > 0)
                {
                    zone.ZoneClass = 0;
                }
                else if (zone.OwnerId != _myTeamId && zone.MaxDrones == 0)
                {
                    zone.ZoneClass = 1;
                }
                else if (zone.OwnerId != _myTeamId && zone.MaxTreat < 2)
                {
                    zone.ZoneClass = 2;
                }
                else if (zone.OwnerId != _myTeamId && zone.MaxTreat > 1)
                {
                    zone.ZoneClass = 3;
                }
                else if (zone.OwnerId == _myTeamId && zone.MaxTreat == 0)
                {
                    zone.ZoneClass = 4;
                }

            }
            #endregion

            #region drones loop
            foreach (var drone in myDrones)
            {

                drone.TargetZones.Clear();
                drone.Target = null;
                foreach (var zone in _zones)
                {
                    TargetZone tZ = new TargetZone { Zone = zone, Distance = GetDistance(drone.Position.X, drone.Position.Y, zone.Center.X, zone.Center.Y) };
                    drone.TargetZones.Add(tZ);
                }

                if (drone.TargetZones.Count(z => z.Distance < 100 && z.Zone.MaxTreat > 0 && z.Zone.OwnerId == _myTeamId) > 0)
                {
                    drone.DroneClass = 0;
                }
                else if (drone.TargetZones.Count(z => z.Distance < 300 && z.Zone.OwnerId != _myTeamId) > 0)
                {
                    drone.DroneClass = 1;
                }
                else
                {
                    drone.DroneClass = 2;
                }

            }

            #endregion

            GetTargetZone(_zones, myDrones);

            foreach (Drone drone in myDrones)
            {
                string cords;
                if (drone.Target == null)
                {
                    TargetZone tz = drone.TargetZones.OrderBy(o => o.Distance).FirstOrDefault(f => f.Zone.OwnerId == _myTeamId);
                    if (tz == null)
                    {
                        Point wheretogo = GetGravityPoint(_zones);
                        cords = (wheretogo.X) + " " + (wheretogo.Y);
                    }
                    else
                    {
                        cords = (tz.Zone.Center.X) + " " + (tz.Zone.Center.Y);
                    }

                }
                else
                {
                    cords = (drone.Target.Center.X) + " " + (drone.Target.Center.Y);
                }
                Console.WriteLine(cords);
            }

            //debugger part
            //foreach (var zone in _zones.OrderBy(z => z.ZoneClass).ThenBy(z => z.BestDistance))
            //{

            //		Console.Error.WriteLine("zona " + zone.ZoneId + " klasa " + zone.ZoneClass);

            //}
            //Console.Error.WriteLine("===========================");
            //foreach (var drone in myDrones)
            //{
            //	Console.Error.WriteLine("dron " + drone.DroneClass);
            //}
        }