コード例 #1
0
ファイル: MyStrategyInit.cs プロジェクト: wampirr/AiCup
        public static void Initialize()
        {
            var facilities = World.Facilities
                             .Select(x => new AFacility(x))
                             .OrderBy(x => x.Id)
                             .ToArray();

            if (TerrainType == null)
            {
                TerrainType = World.TerrainByCellXY;
                WeatherType = World.WeatherByCellXY;
                FacilityIdx = new int[TerrainType.Length][];
                for (var i = 0; i < TerrainType.Length; i++)
                {
                    FacilityIdx[i] = new int[TerrainType[i].Length];
                    for (var j = 0; j < TerrainType[i].Length; j++)
                    {
                        FacilityIdx[i][j] = -1;
                        for (var k = 0; k < facilities.Length; k++)
                        {
                            if (facilities[k].ContainsPoint(new Point((i + 0.5) * G.CellSize, (j + 0.5) * G.CellSize)))
                            {
                                FacilityIdx[i][j] = k;
                            }
                        }
                    }
                }
            }

            var nuclears = World.Players
                           .Where(player => player.NextNuclearStrikeVehicleId != -1)
                           .Select(player => new ANuclear(
                                       player.NextNuclearStrikeX,
                                       player.NextNuclearStrikeY,
                                       player.IsMe,
                                       player.NextNuclearStrikeVehicleId,
                                       player.NextNuclearStrikeTickIndex - World.TickIndex)
                                   )
                           .ToArray();

            Logger.CumulativeOperationStart("VO Update");
            VehiclesObserver.Update();
            Logger.CumulativeOperationEnd("VO Update");

            MoveObserver.Init();
            var prevEnv = Environment;

            Environment = new Sandbox(VehiclesObserver.VehicleById.Values, nuclears, facilities)
            {
                TickIndex = World.TickIndex
            };

            Logger.CumulativeOperationStart("VO Update2");
            VehiclesObserver.Update2(prevEnv, Environment);
            Logger.CumulativeOperationEnd("VO Update2");

            OppClusters = Clustering.GetClustersSimple(
                Environment.OppVehicles.Concat(VehiclesObserver.OppUncheckedVehicles.Values).ToArray(),
                Const.ClusteringMargin
                );

            if (!G.IsAerialButerDetected && World.TickIndex < 1500 && OppClusters.Count < 20)
            {
                foreach (var cl1 in OppClusters)
                {
                    if (cl1.CountByType[(int)VehicleType.Fighter] > 30)
                    {
                        foreach (var cl2 in OppClusters)
                        {
                            if (cl2.CountByType[(int)VehicleType.Helicopter] > 30)
                            {
                                var inter = cl1.BoundingRect.IntersectionWith(cl2.BoundingRect);
                                if (inter != null && inter.Area >= cl1.BoundingRect.Area * 0.7)
                                {
                                    G.IsAerialButerDetected = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            NewGroupMinSize = Math.Min(33, (int)(Environment.MyVehicles.Count * 44 / 500.0));

            var newVehicles = Environment.MyVehicles.Where(x => x.Groups == 0).ToArray();

            var ungroupedEnv = new Sandbox(
                newVehicles,
                new ANuclear[] { },
                new AFacility[] { },
                clone: true
                );

            MyUngroupedClusters = G.IsFacilitiesEnabled
                ? Clustering.GetClustersSimple(ungroupedEnv.MyVehicles.ToArray(), Const.ClusteringMargin * 2)
                : new List <VehiclesCluster>();
        }
コード例 #2
0
        public void Move(Player me, World world, Game game, Move move)
        {
            World         = world;
            Me            = me;
            Opp           = world.GetOpponentPlayer();
            ResultingMove = new AMove();

            _myLastScore  = Me.Score;
            _oppLastScore = Opp.Score;


#if DEBUG
            while (Visualizer.Visualizer.Pause)
            {
                // pause here
                Thread.Sleep(20);
            }
#endif
            Logger.TimerStart();
            if (Me.NextNuclearStrikeVehicleId != -1)
            {
                Logger.TimerStart();
            }

            _move(game);
            Logger.CumulativeOperationPrintAndReset(2);
            if (world.TickIndex % 500 == 0)
            {
                Logger.CumulativeOperationSummary();
            }
            ResultingMove.ApplyTo(move);

            if (Me.NextNuclearStrikeVehicleId != -1)
            {
                Logger.TimerEndLog("AllN", 1);
            }
            Logger.TimerEndLog("All", 0);
#if DEBUG
            Visualizer.Visualizer.CreateForm();

            if (World.TickIndex == 0)
            {
                Visualizer.Visualizer.LookAt = new Point(0, 0);
                Visualizer.Visualizer.Zoom   = 0.5;
            }
            Visualizer.Visualizer.SegmentsDrawQueue.AddRange(VisualSegments);
            Visualizer.Visualizer.Draw();
            if (world.TickIndex >= Visualizer.Visualizer.DrawSince)
            {
                var timer = new Stopwatch();
                timer.Start();
                while (!Visualizer.Visualizer.Done /* || timer.ElapsedMilliseconds < 13*/)
                {
                    Thread.Sleep(10);
                }
                timer.Stop();
            }
#endif

            MoveObserver.Update();
        }