예제 #1
0
        static async Task Main(string[] args)
        {
            var scoreFilePreffix = GetProgramArgument(args, SCORE_PREFFIX_ARG);

            _globalServiceContainer = new ServiceContainer();
            _startUp = new Startup();
            _startUp.RegisterServices(_globalServiceContainer);

            LoadBotAssembly("cdt", "Zilon.Bot.Players.LightInject.dll", _globalServiceContainer, _globalServiceContainer);

            var humanActor = await CreateSectorAsync();

            var gameLoop           = _sectorServiceContainer.GetInstance <IGameLoop>();
            var botActorTaskSource = _sectorServiceContainer.GetInstance <ISectorActorTaskSource>("bot");

            ConfigureBot(args, botActorTaskSource);

            var botExceptionCount = 0;
            var envExceptionCount = 0;
            var iterationCounter  = 1;

            while (!humanActor.Person.Survival.IsDead && iterationCounter <= ITERATION_LIMIT)
            {
                try
                {
                    var humanPersonHp = humanActor.Person
                                        .Survival
                                        .Stats
                                        .Single(x => x.Type == SurvivalStatType.Health)
                                        .Value;

                    var hexNode = (HexNode)humanActor.Node;

                    Console.WriteLine($"Current HP: {humanPersonHp} Node {humanActor.Node}");

                    gameLoop.Update();
                }
                catch (ActorTaskExecutionException exception)
                {
                    AppendException(exception, scoreFilePreffix);

                    var monsterActorTaskSource = _sectorServiceContainer.GetInstance <IActorTaskSource>("monster");
                    if (exception.ActorTaskSource != monsterActorTaskSource)
                    {
                        botExceptionCount++;

                        if (botExceptionCount >= BOT_EXCEPTION_LIMIT)
                        {
                            AppendFail(_globalServiceContainer, scoreFilePreffix);
                            throw;
                        }
                    }
                    else
                    {
                        envExceptionCount++;
                        CheckEnvExceptions(envExceptionCount, exception);
                        Console.WriteLine($"[.] {exception.Message}");
                    }
                }
                catch (Exception exception)
                {
                    AppendException(exception, scoreFilePreffix);

                    envExceptionCount++;
                    CheckEnvExceptions(envExceptionCount, exception);
                    Console.WriteLine($"[.] {exception.Message}");
                }

                if (_changeSector)
                {
                    humanActor = await CreateSectorAsync();

                    gameLoop = _sectorServiceContainer.GetInstance <IGameLoop>();

                    _changeSector = false;
                }

                iterationCounter++;
            }
            ;

            var mode         = GetProgramArgument(args, BOT_MODE_ARG);
            var scoreManager = _globalServiceContainer.GetInstance <IScoreManager>();

            WriteScores(_globalServiceContainer, scoreManager, mode, scoreFilePreffix);

            if (!HasProgramArgument(args, SERVER_RUN_ARG))
            {
                Console.ReadLine();
            }
        }