Esempio n. 1
0
        private void _move(Game game)
        {
            Const.Initialize(World, game);
            Initialize();

            GroupsManager.Update(Environment);

            if (World.TickIndex == 0)
            {
                MoveFirstTicks();
            }
            ActionsQueue.Process();
            var ret = !MoveQueue.Free;

            MoveQueue.Run();
            if (ret)
            {
                return;
            }

            if (Me.RemainingActionCooldownTicks > 0)
            {
                return;
            }

            if (GroupsManager.MyGroups.Count == 0)
            {
                return;
            }

            var actionsBaseInterval = MoveObserver.ActionsBaseInterval;

            if (MyUngroupedClusters.Any(x => x.Count >= NewGroupMinSize))
            {
                actionsBaseInterval++;
            }
            if (World.TickIndex % actionsBaseInterval == 0 ||
                MoveObserver.AvailableActions >= 4 && FirstMovesCompleted && World.TickIndex >= _noMoveLastTick + actionsBaseInterval ||
                Environment.Nuclears.Any(x => x.RemainingTicks >= G.TacticalNuclearStrikeDelay - 2))
            {
                var nuclearMove = NuclearStrategy();
                if (nuclearMove != null)
                {
                    ResultingMove = nuclearMove;
                    return;
                }

                Logger.CumulativeOperationStart("Unstuck");
                var unstuckMove = UnstuckStrategy();
                Logger.CumulativeOperationEnd("Unstuck");
                if (unstuckMove != null)
                {
                    Console.WriteLine("Unstuck");
                    ResultingMove = unstuckMove[0];
                    for (var i = 1; i < unstuckMove.Length; i++)
                    {
                        MoveQueue.Add(unstuckMove[i]);
                    }
                    return;
                }

                var mainMove = MainLoopStrategy(true);
                _doMainsCount++;
                _doMainLastGroup = mainMove.Item2;
                foreach (var move in mainMove.Item1)
                {
                    if (move.Action == ActionType.Scale && move.Factor > 1)
                    {
                        _doMainLastUnscale[mainMove.Item2.Group] = new Tuple <int, AMove>(World.TickIndex, move);
                    }
                }
                foreach (var groupId in _doMainLastUnscale.Keys.ToArray())
                {
                    if (_doMainLastUnscale[groupId].Item1 + 10 + G.TacticalNuclearStrikeDelay < World.TickIndex)
                    {
                        _doMainLastUnscale.Remove(groupId);
                    }
                }

                if (mainMove.Item1[0].Action == null || mainMove.Item1[0].Action == ActionType.None)
                {
                    _noMoveLastTick = World.TickIndex;
                }

                ResultingMove = mainMove.Item1[0];
                for (var i = 1; i < mainMove.Item1.Length; i++)
                {
                    var mv = mainMove.Item1[i];
                    MoveQueue.Add(mv);
                    if (mv.Action == ActionType.Assign && mainMove.Item1[0].VehicleType != null)
                    {
                        GroupsManager.AddPendingGroup(new MyGroup(mv.Group, mainMove.Item1[0].VehicleType.Value));
                    }
                }
                if (mainMove.Item1.Length >= 3)
                {
                    var nearestFacility = Environment.Facilities.ArgMin(
                        f => f.Center.GetDistanceTo2(ResultingMove.Rect.Center));
                    var changeProdMove = ChangeFactoryProduction(nearestFacility);
                    if (changeProdMove != null)
                    {
                        MoveQueue.Add(changeProdMove);
                    }
                }
            }

            if (ResultingMove == null || ResultingMove.Action == null || ResultingMove.Action == ActionType.None)
            {
                if (FirstMovesCompleted)
                {
                    var facilitiesMove = FacilitiesStrategy();
                    if (facilitiesMove != null)
                    {
                        ResultingMove = facilitiesMove;
                    }
                }
            }
        }