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

            var serviceCollection = new ServiceCollection();

            _startUp = new Startup();
            _startUp.RegisterServices(serviceCollection);

            var botSettings = new BotSettings
            {
                Mode = ArgumentHelper.GetProgramArgument(args, BOT_MODE_ARG)
            };

            var autoPlayEngine = new AutoplayEngine(_startUp, botSettings, scoreFilePreffix);

            var serviceProvider = serviceCollection.BuildServiceProvider();

            LoadBotAssembly("cdt", "Zilon.Bot.Players.NetCore.dll", serviceCollection, serviceProvider);

            serviceProvider = serviceCollection.BuildServiceProvider();

            var startPerson = PersonCreateHelper.CreateStartPerson(serviceProvider);

            await autoPlayEngine.StartAsync(startPerson, serviceProvider);

            Console.WriteLine(autoPlayEngine.LogOutput);

            if (!ArgumentHelper.HasProgramArgument(args, SERVER_RUN_ARG))
            {
                Console.ReadLine();
            }
        }
Beispiel #2
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var schemeCatalog = ArgumentHelper.GetProgramArgument(args, "schemeCatalog");
            var resultPath    = ArgumentHelper.GetProgramArgument(args, "resultPath");

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

            var startTime = DateTime.UtcNow;

            var resultFolderPreffix = startTime.ToString("yyyyMMdd-HHmmss");
            var resultFolder        = Path.Combine(resultPath, resultFolderPreffix);

            Directory.CreateDirectory(resultFolder);

            var iteration = 0;

            while (true)
            {
                iteration++;

                var worldGenerator = _globalServiceContainer.GetInstance <IWorldGenerator>();

                var result = await worldGenerator.GenerateGlobeAsync();

                var resultRealmsFile   = $"realm{iteration:D5}.bmp";
                var resultBranchesFile = $"branches{iteration:D5}.bmp";

                result.Globe.Save(resultFolder, resultRealmsFile, resultBranchesFile);
                Console.WriteLine($"Iteration {iteration:D5} complete");
            }
        }
Beispiel #3
0
        private static void ConfigureBot(string[] args, ISectorActorTaskSource actorTaskSource)
        {
            var botSettings = new BotSettings
            {
                Mode = ArgumentHelper.GetProgramArgument(args, BOT_MODE_ARG)
            };

            actorTaskSource.Configure(botSettings);
        }
Beispiel #4
0
        private static void Main(string[] args)
        {
            var imagePath  = ArgumentHelper.GetProgramArgument(args, "imagePath");
            var outputPath = ArgumentHelper.GetProgramArgument(args, "outputPath");

            var files = Directory.GetFiles(imagePath, "*.png");

            foreach (var file in files)
            {
                HandleFile(outputPath, file);
            }
        }
        /// <summary>
        /// Создаёт кастомный конфиг бенчей на основе аргументов командной строки.
        /// </summary>
        /// <param name="args"> Аргументы командной строки. </param>
        /// <returns> Возвращает объект конфигурации. </returns>
        public static Config CreateBenchConfig(string[] args)
        {
            var buildNumber          = ArgumentHelper.GetProgramArgument(args, "BUILD_NUMBER");
            var iterationCountString = ArgumentHelper.GetProgramArgument(args, "ITERATION_COUNT");
            var iterationCount       = int.Parse(iterationCountString, System.Globalization.CultureInfo.InvariantCulture);
            var monoName             = "mono";
            var monoPath             = ArgumentHelper.GetProgramArgument(args, "MONO_PATH");
            var artifactPath         = ArgumentHelper.GetProgramArgument(args, "ARTIFACT_PATH");

            var config = new Config(buildNumber, iterationCount, monoName, monoPath, artifactPath);

            return(config);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var schemePath = ArgumentHelper.GetProgramArgument(args, "SchemeCatalog");

            var monoPath       = ArgumentHelper.GetProgramArgument(args, "MonoPath");
            var artefactsPath  = ArgumentHelper.GetProgramArgument(args, "ArtefactsPath");
            var iterationCount = int.Parse(ArgumentHelper.GetProgramArgument(args, "IterationCount"));

            var config = CreateBenchConfig(monoPath, artefactsPath, schemePath, iterationCount);

            BenchmarkRunner.Run <MoveBench>(config);
            BenchmarkRunner.Run <CreateGlobeBench>(config);
        }
Beispiel #7
0
        public void Run(params string[] args)
        {
            _logger.LogTrace("[x] START");

            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            _pathToEnv   = ArgumentHelper.GetProgramArgument(args, "env");
            _launchCount = int.Parse(ArgumentHelper.GetProgramArgument(args, "launchCount"));
            _scorePrefix = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
                           .Replace(":", "_")
                           .Replace(".", "_");

            var parallel = ArgumentHelper.GetProgramArgument(args, "parallel");

            _isInfinite = ArgumentHelper.HasProgramArgument(args, "infinite");
            _botMode    = ArgumentHelper.GetProgramArgument(args, "mode");
            _scorePath  = ArgumentHelper.GetProgramArgument(args, "output");

            _botCatalog  = ArgumentHelper.GetProgramArgument(args, "botCatalog");
            _botAssembly = ArgumentHelper.GetProgramArgument(args, "botAssembly");

            _schemeCatalogPath = ArgumentHelper.GetProgramArgument(args, "schemeCatalogPath");

            _shutdownTokenSource = new CancellationTokenSource();
            _shutdownToken       = _shutdownTokenSource.Token;

            do
            {
                if (_isInfinite)
                {
                    _logger.LogTrace($"[x] INFINITE COUNTER {_infiniteCounter}");
                }

                if (!string.IsNullOrWhiteSpace(parallel))
                {
                    RunParallel(int.Parse(parallel), _logger);
                }
                else
                {
                    RunLinear(_logger);
                }

                _infiniteCounter++;
                if (_infiniteCounter == ulong.MaxValue)
                {
                    _infiniteCounter = 0;
                }
            } while (_isInfinite);

            _logger.LogTrace("[x] COMPLETE");
        }
Beispiel #8
0
        private static SectorSchemeResult GetSectorScheme(string[] args, ISchemeService schemeService)
        {
            var locationSchemeSid = ArgumentHelper.GetProgramArgument(args, Args.LOCATION_SCHEME_SID_ARG_NAME);
            var sectorSchemeSid   = ArgumentHelper.GetProgramArgument(args, Args.SECTOR_SCHEME_SID_ARG_NAME);

            if (string.IsNullOrWhiteSpace(locationSchemeSid) && string.IsNullOrWhiteSpace(sectorSchemeSid))
            {
                // Если схемы не указаны, то берём случайную схему.
                // Это используется на билд-сервере, чтобы случайно проверить несколько схем.

                var locationSchemes = schemeService.GetSchemes <ILocationScheme>()
                                      .Where(x => x.SectorLevels != null && x.SectorLevels.Any())
                                      .ToArray();
                var locationSchemeIndex = _random.Next(0, locationSchemes.Length);
                var locationScheme      = locationSchemes[locationSchemeIndex];

                var sectorSchemes     = locationScheme.SectorLevels;
                var sectorSchemeIndex = _random.Next(0, sectorSchemes.Length);
                var sectorScheme      = sectorSchemes[sectorSchemeIndex];

                Log.Info($"SCHEME: {locationScheme.Sid} - {sectorScheme.Sid}(index:{sectorSchemeIndex})");

                var result = new SectorSchemeResult(locationScheme, sectorScheme);

                return(result);
            }
            else
            {
                // Если схемы заданы, то строим карту на их основе.
                // Это будет использовано для отладки.

                var locationScheme = schemeService.GetScheme <ILocationScheme>(locationSchemeSid);
                if (locationScheme == null)
                {
                    throw new SectorGeneratorException($"Не найдена схема локации {locationSchemeSid}.");
                }

                var sectorScheme = locationScheme.SectorLevels.SingleOrDefault(x => x.Sid == sectorSchemeSid);
                if (sectorScheme == null)
                {
                    throw new SectorGeneratorException($"Не найдена схема сектора {sectorSchemeSid}.");
                }

                var result = new SectorSchemeResult(locationScheme, sectorScheme);

                return(result);
            }
        }
Beispiel #9
0
        private static string GetOutputPath(string[] args)
        {
            var outputPath = ArgumentHelper.GetProgramArgument(args, Args.OUT_PATH_ARG_NAME);

            if (string.IsNullOrWhiteSpace(outputPath))
            {
                return(null);
            }

            try
            {
                Path.GetFullPath(outputPath);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
                return(null);
            }

            return(outputPath);
        }
Beispiel #10
0
        private static async Task Main(string[] args)
        {
            var scoreFilePreffix = ArgumentHelper.GetProgramArgument(args, SCORE_PREFFIX_ARG);

            var serviceCollection = new ServiceCollection();

            _startUp = new Startup();
            _startUp.RegisterServices(serviceCollection);

            var botSettings = new BotSettings
            {
                Mode = ArgumentHelper.GetProgramArgument(args, BOT_MODE_ARG)
            };

            var serviceProvider = serviceCollection.BuildServiceProvider();

            LoadBotAssembly("cdt", "Zilon.Bot.Players.NetCore.dll", serviceCollection, serviceProvider);
            var serviceProviderWithDynamicBotServices = serviceCollection.BuildServiceProvider();

            var globeInitializer = serviceProviderWithDynamicBotServices.GetRequiredService <IGlobeInitializer>();

            var autoPlayEngine = new AutoplayEngine(_startUp, botSettings, scoreFilePreffix, globeInitializer);

            var player      = serviceProvider.GetRequiredService <IPlayer>();
            var startPerson = player.MainPerson;

            var globe = await autoPlayEngine.CreateGlobeAsync();

            var autoplayContext = new FollowSinglePersonAutoplayContext(startPerson);

            await autoPlayEngine.StartAsync(globe, autoplayContext);

            Console.WriteLine(autoPlayEngine.LogOutput);

            if (!ArgumentHelper.HasProgramArgument(args, SERVER_RUN_ARG))
            {
                Console.ReadLine();
            }
        }
Beispiel #11
0
        private static int GetDiceSeed(string[] args)
        {
            var diceSeedString = ArgumentHelper.GetProgramArgument(args, Args.DICE_SEED_ARG_NAME);

            int diceSeed;

            if (string.IsNullOrWhiteSpace(diceSeedString))
            {
                diceSeed = _random.Next(0, int.MaxValue);
            }
            else
            {
                if (!int.TryParse(diceSeedString, out diceSeed))
                {
                    throw new SectorGeneratorException($"Зерно рандома задано некорректно: {diceSeedString}.");
                }
            }

            Log.Info($"DICE SEED: {diceSeed}");

            return(diceSeed);
        }
Beispiel #12
0
        static async Task Main(string[] args)
        {
            var scoreFilePreffix = ArgumentHelper.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;

                    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         = ArgumentHelper.GetProgramArgument(args, BOT_MODE_ARG);
            var scoreManager = _globalServiceContainer.GetInstance <IScoreManager>();

            WriteScores(_globalServiceContainer, scoreManager, mode, scoreFilePreffix);

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