コード例 #1
0
        public async Task Process()
        {
            using (var stopwatch = new SimpleStopwatch())
            {
                var arena = await _arenaLogic.GetArena();

                var elapsedArena = stopwatch.ElapsedMilliseconds;

                var bots = await _botLogic.GetAllLiveBots();

                var elapsedBots = stopwatch.ElapsedMilliseconds - elapsedArena;

                var context = ProcessingContext.Build(arena, bots);

                await _preprocessor.Go(context);

                var elapsedPreprocessing = stopwatch.ElapsedMilliseconds - elapsedBots - elapsedArena;

                await _processor.Go(context);

                var elapsedProcessing = stopwatch.ElapsedMilliseconds - elapsedPreprocessing - elapsedBots - elapsedArena;

                await _postprocessor.Go(context);

                var elapsedPostprocessing = stopwatch.ElapsedMilliseconds - elapsedProcessing - elapsedPreprocessing - elapsedBots - elapsedArena;

                await _botLogic.UpdateBots(context.Bots);

                var elapsedUpdateBots = stopwatch.ElapsedMilliseconds - elapsedPostprocessing - elapsedProcessing - elapsedPreprocessing - elapsedBots - elapsedArena;

                //await _messageLogic.CreateMessages(context.Messages);
                var elapsedCreateMessages = stopwatch.ElapsedMilliseconds - elapsedUpdateBots - elapsedPostprocessing - elapsedProcessing - elapsedPreprocessing - elapsedBots - elapsedArena;

                Console.WriteLine(
                    $"{elapsedArena}ms, {elapsedBots}ms, {elapsedPreprocessing}ms, {elapsedProcessing}ms, {elapsedPostprocessing}ms, {elapsedUpdateBots}ms, {elapsedCreateMessages}ms");
            }
        }
コード例 #2
0
ファイル: Middleware.cs プロジェクト: swipswaps/CSharpWars
        public async Task Process()
        {
            using var stopwatch = new SimpleStopwatch();

            var arena = await _arenaLogic.GetArena();

            var elapsedArena = stopwatch.ElapsedMilliseconds;

            var bots = await _botLogic.GetAllLiveBots();

            var elapsedBots = stopwatch.ElapsedMilliseconds - elapsedArena;

            var context = ProcessingContext.Build(arena, bots);

            await _preprocessor.Go(context);

            var elapsedPreprocessing = stopwatch.ElapsedMilliseconds - elapsedBots - elapsedArena;

            await _processor.Go(context);

            var elapsedProcessing = stopwatch.ElapsedMilliseconds - elapsedPreprocessing - elapsedBots - elapsedArena;

            await _postprocessor.Go(context);

            var elapsedPostprocessing = stopwatch.ElapsedMilliseconds - elapsedProcessing - elapsedPreprocessing - elapsedBots - elapsedArena;

            await _botLogic.UpdateBots(context.Bots);

            var elapsedUpdateBots = stopwatch.ElapsedMilliseconds - elapsedPostprocessing - elapsedProcessing - elapsedPreprocessing - elapsedBots - elapsedArena;

            //await _messageLogic.CreateMessages(context.Messages);
            var elapsedCreateMessages = stopwatch.ElapsedMilliseconds - elapsedUpdateBots - elapsedPostprocessing - elapsedProcessing - elapsedPreprocessing - elapsedBots - elapsedArena;

            _logger.LogInformation("{elapsedArena}ms, {elapsedBots}ms, {elapsedPreprocessing}ms, {elapsedProcessing}ms, {elapsedPostprocessing}ms, {elapsedUpdateBots}ms, {elapsedCreateMessages}ms",
                                   elapsedArena, elapsedBots, elapsedPreprocessing, elapsedProcessing, elapsedPostprocessing, elapsedUpdateBots, elapsedCreateMessages);
        }
コード例 #3
0
        public Task Go(ProcessingContext context)
        {
            var botProperties = context.GetOrderedBotProperties();

            foreach (var botProperty in botProperties)
            {
                try
                {
                    var bot       = context.Bots.Single(x => x.Id == botProperty.BotId);
                    var botResult = Move.Build(botProperty, _randomHelper).Go();
                    bot.Orientation    = botResult.Orientation;
                    bot.FromX          = bot.X;
                    bot.FromY          = bot.Y;
                    bot.X              = botResult.X;
                    bot.Y              = botResult.Y;
                    bot.CurrentHealth  = botResult.CurrentHealth;
                    bot.CurrentStamina = botResult.CurrentStamina;
                    bot.Move           = botResult.Move;
                    bot.Memory         = botResult.Memory.Serialize();
                    bot.LastAttackX    = botResult.LastAttackX;
                    bot.LastAttackY    = botResult.LastAttackY;

                    context.UpdateBotProperties(bot);

                    foreach (var otherBot in context.Bots.Where(x => x.Id != bot.Id))
                    {
                        otherBot.CurrentHealth -= botResult.GetInflictedDamage(otherBot.Id);
                        var teleportation = botResult.GetTeleportation(otherBot.Id);
                        if (teleportation != (-1, -1))
                        {
                            otherBot.X = teleportation.X;
                            otherBot.Y = teleportation.Y;
                        }

                        var otherBotProperties = botProperties.Single(x => x.BotId == otherBot.Id);
                        otherBotProperties.Update(otherBot);
                    }
                }
                catch { }
            }

            foreach (var bot in context.Bots)
            {
                if (bot.CurrentHealth <= 0)
                {
                    bot.CurrentHealth = 0;
                    bot.TimeOfDeath   = DateTime.UtcNow;
                    if (bot.Move != PossibleMoves.SelfDestruct)
                    {
                        bot.Move = PossibleMoves.Died;
                    }
                }

                if (bot.CurrentStamina <= 0)
                {
                    bot.CurrentStamina = 0;
                }
            }

            return(Task.CompletedTask);
        }
コード例 #4
0
ファイル: Processor.cs プロジェクト: swipswaps/CSharpWars
 public async Task Go(ProcessingContext context)
 {
     var botProcessing = context.Bots.Select(bot => _botProcessingFactory.Process(bot, context));
     await Task.WhenAll(botProcessing);
 }
コード例 #5
0
 public async Task Go(ProcessingContext context)
 {
     throw new NotImplementedException();
 }