public void Executing_A_Teleport_Into_An_Empty_Spot_Should_Work() { // Arrange var bot = new BotDto { CurrentHealth = 100, X = 0, Y = 0, Orientation = PossibleOrientations.North, CurrentStamina = 10 }; var arena = new ArenaDto { Width = 5, Height = 2 }; var botProperties = BotProperties.Build(bot, arena, new List <BotDto>()); botProperties.CurrentMove = PossibleMoves.Teleport; botProperties.MoveDestinationX = 4; botProperties.MoveDestinationY = 1; var randomHelper = new Mock <IRandomHelper>(); // Act var result = Move.Build(botProperties, randomHelper.Object).Go(); // Assert result.Should().NotBeNull(); result.X.Should().Be(botProperties.MoveDestinationX); result.Y.Should().Be(botProperties.MoveDestinationY); result.Move.Should().Be(PossibleMoves.Teleport); }
public void Executing_A_Teleport_Into_An_Invalid_Spot_Should_Randomly_Teleport(int destinationX, int destinationY) { // Arrange var bot = new BotDto { CurrentHealth = 100, X = 0, Y = 0, Orientation = PossibleOrientations.North, CurrentStamina = 10 }; var arena = new ArenaDto { Width = 5, Height = 1 }; var botProperties = BotProperties.Build(bot, arena, new List <BotDto>()); botProperties.CurrentMove = PossibleMoves.Teleport; botProperties.MoveDestinationX = destinationX; botProperties.MoveDestinationY = destinationY; var randomHelper = new Mock <IRandomHelper>(); var randomX = 4; var randomY = 0; // Mock randomHelper.Setup(x => x.Get(It.Is <int>(w => w == arena.Width))).Returns(randomX); randomHelper.Setup(x => x.Get(It.Is <int>(w => w == arena.Height))).Returns(randomY); // Act var result = Move.Build(botProperties, randomHelper.Object).Go(); // Assert result.Should().NotBeNull(); result.X.Should().Be(randomX); result.Y.Should().Be(randomY); result.Move.Should().Be(PossibleMoves.Teleport); }
public void Executing_A_Teleport_Into_An_Enemy_Should_Switch_Places() { // Arrange var bot = new BotDto { CurrentHealth = 100, X = 0, Y = 1, Orientation = PossibleOrientations.North, CurrentStamina = 10 }; var victim = new BotDto { Id = Guid.NewGuid(), CurrentHealth = 100, X = 4, Y = 0 }; var arena = new ArenaDto { Width = 5, Height = 2 }; var botProperties = BotProperties.Build(bot, arena, new List <BotDto>(new[] { victim })); botProperties.CurrentMove = PossibleMoves.Teleport; botProperties.MoveDestinationX = 4; botProperties.MoveDestinationY = 0; var randomHelper = new Mock <IRandomHelper>(); // Act var result = Move.Build(botProperties, randomHelper.Object).Go(); // Assert result.Should().NotBeNull(); result.X.Should().Be(botProperties.MoveDestinationX); result.Y.Should().Be(botProperties.MoveDestinationY); result.GetTeleportation(victim.Id).X.Should().Be(bot.X); result.GetTeleportation(victim.Id).Y.Should().Be(bot.Y); result.Move.Should().Be(PossibleMoves.Teleport); }
public void Vision_Build_Should_Identify_Bots_Correctly( PossibleOrientations orientation, int x, int y, string playerName, string botName, int expectedBots, int expectedFriendlies, int expectedEnemies) { // Arrange var arena = new ArenaDto(3, 3); var playerBot = new BotDto { Id = Guid.NewGuid(), X = 1, Y = 1, PlayerName = playerName, Orientation = orientation }; var otherBot = new BotDto { Id = Guid.NewGuid(), X = x, Y = y, PlayerName = botName }; var bots = new List <BotDto>(new[] { playerBot, otherBot }); var botProperties = BotProperties.Build(playerBot, arena, bots); // Act var result = Vision.Build(botProperties); // Assert result.Should().NotBeNull(); result.Bots.Should().NotBeNull(); result.Bots.Should().HaveCount(expectedBots); result.FriendlyBots.Should().NotBeNull(); result.FriendlyBots.Should().HaveCount(expectedFriendlies); result.EnemyBots.Should().NotBeNull(); result.EnemyBots.Should().HaveCount(expectedEnemies); }
public async Task Postprocessor_Go_Should_Ignore_Bots_That_Have_Zero_Stamina_Left() { // Arrange var randomHelper = new Mock <IRandomHelper>(); var postprocessor = new Postprocessor(randomHelper.Object); var arena = new ArenaDto { Width = 3, Height = 3 }; var bot = new BotDto { Id = Guid.NewGuid(), X = 1, Y = 1, CurrentHealth = 1, CurrentStamina = 0 }; var bots = new List <BotDto>(new[] { bot }); var context = ProcessingContext.Build(arena, bots); var botProperties = BotProperties.Build(bot, arena, bots); botProperties.CurrentMove = PossibleMoves.WalkForward; context.AddBotProperties(bot.Id, botProperties); // Act await postprocessor.Go(context); // Assert context.Bots.Should().HaveCount(1); context.Bots.Should().ContainEquivalentOf(new BotDto { X = 1, Y = 1, CurrentStamina = 0, Move = PossibleMoves.Idling }, c => c.Including(p => p.X) .Including(p => p.Y) .Including(p => p.CurrentStamina) .Including(p => p.Move)); }
public async Task Postprocessor_Go_Should_Kill_Bots_That_Have_Self_Destructed() { // Arrange var randomHelper = new Mock <IRandomHelper>(); var postprocessor = new Postprocessor(randomHelper.Object); var arena = new ArenaDto { Width = 1, Height = 1 }; var bot = new BotDto { Id = Guid.NewGuid(), CurrentHealth = 1 }; var bots = new List <BotDto>(new[] { bot }); var context = ProcessingContext.Build(arena, bots); var botProperties = BotProperties.Build(bot, arena, bots); botProperties.CurrentMove = PossibleMoves.SelfDestruct; context.AddBotProperties(bot.Id, botProperties); // Act await postprocessor.Go(context); // Assert context.Bots.Should().HaveCount(1); context.Bots.Should().ContainEquivalentOf(new BotDto { Move = PossibleMoves.SelfDestruct, CurrentHealth = 0 }, c => c .Including(p => p.Move) .Including(p => p.CurrentHealth)); }
public async Task BotProcessingFactory_Process_With_Valid_Script_Should_Register_Correct_Move() { // Arrange var botLogic = new Mock <IBotLogic>(); var botScriptCompiler = new BotScriptCompiler(); var botScriptCache = new BotScriptCache(); var logger = new Mock <ILogger <BotProcessingFactory> >(); var botProcessingFactory = new BotProcessingFactory( botLogic.Object, botScriptCompiler, botScriptCache, logger.Object); var arena = new ArenaDto { Width = 4, Height = 3 }; var bot = new BotDto { Id = Guid.NewGuid() }; var bots = new List <BotDto>(new[] { bot }); var context = ProcessingContext.Build(arena, bots); context.AddBotProperties(bot.Id, BotProperties.Build(bot, arena, bots)); var botScript = "WalkForward();".Base64Encode(); // Mock botLogic.Setup(x => x.GetBotScript(It.IsAny <Guid>())).ReturnsAsync(botScript); // Act await botProcessingFactory.Process(bot, context); // Assert context.GetBotProperties(bot.Id).CurrentMove.Should().Be(PossibleMoves.WalkForward); }
public void Walking_Forward_Against_Edge_Should_Be_Ignored(PossibleOrientations orientation) { // Arrange var bot = new BotDto { Orientation = orientation, CurrentHealth = 100, CurrentStamina = 100 }; var arena = new ArenaDto(1, 1); var botProperties = BotProperties.Build(bot, arena, new List <BotDto>()); botProperties.CurrentMove = PossibleMoves.WalkForward; var randomHelper = new Mock <IRandomHelper>(); var move = Move.Build(botProperties, randomHelper.Object); // Act var botResult = move.Go(); // Assert botResult.Should().NotBeNull(); botResult.X.Should().Be(0); botResult.Y.Should().Be(0); botResult.Move.Should().Be(PossibleMoves.Idling); botResult.CurrentStamina.Should().Be(bot.CurrentStamina); }
public void Walking_Forward_Without_Stamina_Should_Be_Ignored() { // Arrange var bot = new BotDto { X = 1, Y = 1 }; var arena = new ArenaDto { Width = 3, Height = 3 }; var botProperties = BotProperties.Build(bot, arena, new List <BotDto>()); botProperties.CurrentMove = PossibleMoves.WalkForward; var randomHelper = new Mock <IRandomHelper>(); var move = Move.Build(botProperties, randomHelper.Object); // Act var botResult = move.Go(); // Assert botResult.Should().NotBeNull(); botResult.X.Should().Be(1); botResult.Y.Should().Be(1); botResult.Move.Should().Be(PossibleMoves.Idling); botResult.CurrentStamina.Should().Be(0); }
public async Task Processor_Go_Should_Call_Into_The_BotProcessingFactory_For_Every_Bot_Provided() { // Arrange var botProcessingFactory = new Mock <IBotProcessingFactory>(); var processor = new Processor(botProcessingFactory.Object); var arena = new ArenaDto { Width = 4, Height = 6 }; var bot1 = new BotDto { Id = Guid.NewGuid() }; var bot2 = new BotDto { Id = Guid.NewGuid() }; var bot3 = new BotDto { Id = Guid.NewGuid() }; var bots = new List <BotDto>(new[] { bot1, bot2, bot3 }); var processingContext = ProcessingContext.Build(arena, bots); // Act await processor.Go(processingContext); // Assert botProcessingFactory.Verify(x => x.Process(It.IsAny <BotDto>(), It.IsAny <ProcessingContext>()), Times.Exactly(3)); }
public void Executing_A_SelfDestruct_Should_Damage_Minimum_Vicinity_Bots_With_Minimum_Damage(int victimX, int victimY) { // Arrange var bot = new BotDto { CurrentHealth = 100, X = 3, Y = 3 }; var victim = new BotDto { Id = Guid.NewGuid(), CurrentHealth = 100, X = victimX, Y = victimY }; var arena = new ArenaDto { Width = 7, Height = 7 }; var botProperties = BotProperties.Build(bot, arena, new List <BotDto>(new[] { victim })); botProperties.CurrentMove = PossibleMoves.SelfDestruct; var expectedDamage = Constants.SELF_DESTRUCT_MIN_DAMAGE; var randomHelper = new Mock <IRandomHelper>(); // Act var result = Move.Build(botProperties, randomHelper.Object).Go(); // Assert result.Should().NotBeNull(); result.GetInflictedDamage(victim.Id).Should().Be(expectedDamage); }
public void BotLogic_CreateBot_Should_Not_Create_A_Bot_In_Rapid_Succession() { // Arrange var randomHelper = new Mock <IRandomHelper>(); var botRepository = new Mock <IRepository <Bot> >(); var scriptRepository = new Mock <IRepository <BotScript> >(); var playerRepository = new Mock <IRepository <Player> >(); var botMapper = new BotMapper(); var botToCreateMapper = new BotToCreateMapper(); var arenaLogic = new Mock <IArenaLogic>(); var configurationHelper = new Mock <IConfigurationHelper>(); IBotLogic botLogic = new BotLogic( randomHelper.Object, botRepository.Object, scriptRepository.Object, playerRepository.Object, botMapper, botToCreateMapper, arenaLogic.Object, configurationHelper.Object); var arenaDto = new ArenaDto(3, 3); var player = new Player { Id = Guid.NewGuid(), LastDeployment = DateTime.UtcNow }; var botToCreateDto = new BotToCreateDto(Guid.NewGuid(), "BotName", 100, 200, "BotScript"); // Mock arenaLogic.Setup(x => x.GetArena()).ReturnsAsync(arenaDto); playerRepository.Setup(x => x.Single(Any.Predicate <Player>())).ReturnsAsync(player); configurationHelper.Setup(x => x.BotDeploymentLimit).Returns(1); // Act Func <Task> act = async() => await botLogic.CreateBot(botToCreateDto); // Assert act.Should().ThrowAsync <LogicException>().WithMessage("You are not allowed to create multiple robots in rapid succession!"); }
public void Executing_A_MeleeAttack_Should_Work_In_The_Four_Possible_Orientations(int victimX, int victimY, PossibleOrientations orientation) { // Arrange var bot = new BotDto { CurrentHealth = 100, X = 1, Y = 1, Orientation = orientation }; var victim = new BotDto { Id = Guid.NewGuid(), CurrentHealth = 100, X = victimX, Y = victimY, Orientation = orientation }; var arena = new ArenaDto { Width = 3, Height = 3 }; var botProperties = BotProperties.Build(bot, arena, new List <BotDto>(new[] { victim })); botProperties.CurrentMove = PossibleMoves.MeleeAttack; var expectedDamage = Constants.MELEE_BACKSTAB_DAMAGE; var randomHelper = new Mock <IRandomHelper>(); // Act var result = Move.Build(botProperties, randomHelper.Object).Go(); // Assert result.Should().NotBeNull(); result.GetInflictedDamage(victim.Id).Should().Be(expectedDamage); }
public void Executing_A_RangedAttack_Into_Thin_Air_Should_Not_Inflict_Damage(Int32 moveDestinationX, Int32 moveDestinationY) { // Arrange var bot = new BotDto { CurrentHealth = 100, X = 1, Y = 1, Orientation = PossibleOrientations.North }; var victim = new BotDto { Id = Guid.NewGuid(), CurrentHealth = 100, X = 1, Y = 0 }; var arena = new ArenaDto { Width = 3, Height = 3 }; var botProperties = BotProperties.Build(bot, arena, new List <BotDto>(new[] { victim })); botProperties.CurrentMove = PossibleMoves.RangedAttack; botProperties.MoveDestinationX = moveDestinationX; botProperties.MoveDestinationY = moveDestinationY; var randomHelper = new Mock <IRandomHelper>(); // Act var result = Move.Build(botProperties, randomHelper.Object).Go(); // Assert result.Should().NotBeNull(); result.GetInflictedDamage(victim.Id).Should().BeZero(); }
public void ProcessingContext_GetOrderedBotProperties_Should_Order_BotProperties() { // Arrange var arena = new ArenaDto(4, 5); var bot1 = new BotDto { Id = Guid.NewGuid() }; var bot2 = new BotDto { Id = Guid.NewGuid() }; var bots = new List <BotDto>(new[] { bot1, bot2 }); var processingContext = ProcessingContext.Build(arena, bots); var botProperties1 = BotProperties.Build(bot1, arena, bots); botProperties1.CurrentMove = PossibleMoves.WalkForward; var botProperties2 = BotProperties.Build(bot2, arena, bots); botProperties2.CurrentMove = PossibleMoves.MeleeAttack; processingContext.AddBotProperties(bot1.Id, botProperties1); processingContext.AddBotProperties(bot2.Id, botProperties2); // Act var result = processingContext.GetOrderedBotProperties(); // Assert result.Should().NotBeNull(); result.Should().ContainInOrder(botProperties2, botProperties1); }
public void Executing_A_RangedAttack_To_A_Victim_Should_Inflict_Damage() { // Arrange var bot = new BotDto { CurrentHealth = 100, X = 1, Y = 1, Orientation = PossibleOrientations.North }; var victim = new BotDto { Id = Guid.NewGuid(), CurrentHealth = 100, X = 1, Y = 0, Orientation = PossibleOrientations.South }; var arena = new ArenaDto { Width = 3, Height = 3 }; var botProperties = BotProperties.Build(bot, arena, new List <BotDto>(new[] { victim })); botProperties.CurrentMove = PossibleMoves.RangedAttack; botProperties.MoveDestinationX = 1; botProperties.MoveDestinationY = 0; var expectedDamage = Constants.RANGED_DAMAGE; var randomHelper = new Mock <IRandomHelper>(); // Act var result = Move.Build(botProperties, randomHelper.Object).Go(); // Assert result.Should().NotBeNull(); result.GetInflictedDamage(victim.Id).Should().Be(expectedDamage); }
private void Walking_Forward_Should_Work(PossibleOrientations orientation, int destinationX, int destinationY) { // Arrange var bot = new BotDto { X = 1, Y = 1, Orientation = orientation, CurrentHealth = 100, CurrentStamina = 100 }; var arena = new ArenaDto(3, 3); var botProperties = BotProperties.Build(bot, arena, new List <BotDto>()); botProperties.CurrentMove = PossibleMoves.WalkForward; var randomHelper = new Mock <IRandomHelper>(); var move = Move.Build(botProperties, randomHelper.Object); // Act var botResult = move.Go(); // Assert botResult.Should().NotBeNull(); botResult.X.Should().Be(destinationX); botResult.Y.Should().Be(destinationY); botResult.Move.Should().Be(PossibleMoves.WalkForward); botResult.CurrentStamina.Should().Be(bot.CurrentStamina - Constants.STAMINA_ON_MOVE); }
public async Task BotProcessingFactory_Process_Without_Valid_Script_Should_Register_ScriptError() { // Arrange var botLogic = new Mock <IBotLogic>(); var botScriptCompiler = new Mock <IBotScriptCompiler>(); var botScriptCache = new Mock <IBotScriptCache>(); var logger = new Mock <ILogger <BotProcessingFactory> >(); var botProcessingFactory = new BotProcessingFactory( botLogic.Object, botScriptCompiler.Object, botScriptCache.Object, logger.Object); var arena = new ArenaDto { Width = 4, Height = 3 }; var bot = new BotDto { Id = Guid.NewGuid() }; var bots = new List <BotDto>(new[] { bot }); var context = ProcessingContext.Build(arena, bots); context.AddBotProperties(bot.Id, BotProperties.Build(bot, arena, bots)); // Act await botProcessingFactory.Process(bot, context); // Assert context.GetBotProperties(bot.Id).CurrentMove.Should().Be(PossibleMoves.ScriptError); }
public void BotResult_Build_From_BotProperties_Should_Copy_Properties() { // Arrange var bot = new BotDto { X = 1, Y = 2, Orientation = PossibleOrientations.East, CurrentHealth = 99, CurrentStamina = 999, Memory = new Dictionary<String, String>().Serialize() }; var arena = new ArenaDto { Width = 1, Height = 1 }; var botProperties = BotProperties.Build(bot, arena, new List<BotDto>()); botProperties.MoveDestinationX = 3; botProperties.MoveDestinationY = 4; // Act var result = BotResult.Build(botProperties); // Assert result.Should().NotBeNull(); result.X.Should().Be(bot.X); result.Y.Should().Be(bot.Y); result.Orientation.Should().Be(bot.Orientation); result.CurrentHealth.Should().Be(bot.CurrentHealth); result.CurrentStamina.Should().Be(bot.CurrentStamina); result.Memory.Should().BeEquivalentTo(bot.Memory.Deserialize<Dictionary<String, String>>()); result.Messages.Should().BeEquivalentTo(new List<String>()); result.Move.Should().Be(PossibleMoves.Idling); result.LastAttackX.Should().Be(botProperties.MoveDestinationX); result.LastAttackY.Should().Be(botProperties.MoveDestinationY); }
public async Task Postprocessor_Go_Should_Allow_A_Bot_To_Teleport_Onto_Another_Idling_Bot() { // Arrange var randomHelper = new Mock <IRandomHelper>(); var postprocessor = new Postprocessor(randomHelper.Object); var arena = new ArenaDto(4, 1); var bot1 = new BotDto { Id = Guid.NewGuid(), X = 0, Y = 0, Orientation = PossibleOrientations.East, CurrentStamina = 15, CurrentHealth = 1 }; var bot2 = new BotDto { Id = Guid.NewGuid(), X = 3, Y = 0, Orientation = PossibleOrientations.West, CurrentStamina = 1, CurrentHealth = 1 }; var bots = new List <BotDto>(new[] { bot1, bot2 }); var context = ProcessingContext.Build(arena, bots); var bot1Properties = BotProperties.Build(bot1, arena, bots); var bot2Properties = BotProperties.Build(bot2, arena, bots); bot1Properties.CurrentMove = PossibleMoves.Teleport; bot1Properties.MoveDestinationX = 3; bot1Properties.MoveDestinationY = 0; bot2Properties.CurrentMove = PossibleMoves.Idling; context.AddBotProperties(bot1.Id, bot1Properties); context.AddBotProperties(bot2.Id, bot2Properties); // Act await postprocessor.Go(context); // Assert context.Bots.Should().HaveCount(2); context.Bots.Should().ContainEquivalentOf(new BotDto { X = 3, Y = 0, FromX = 0, FromY = 0, Orientation = PossibleOrientations.East, CurrentStamina = 15 - Constants.STAMINA_ON_TELEPORT, Move = PossibleMoves.Teleport }, c => c .Including(p => p.X) .Including(p => p.Y) .Including(p => p.FromX) .Including(p => p.FromY) .Including(p => p.Orientation) .Including(p => p.CurrentStamina) .Including(p => p.Move)); context.Bots.Should().ContainEquivalentOf(new BotDto { X = 0, Y = 0, Orientation = PossibleOrientations.West, CurrentStamina = 1, Move = PossibleMoves.Idling }, c => c.Including(p => p.X) .Including(p => p.Y) .Including(p => p.Orientation) .Including(p => p.CurrentStamina) .Including(p => p.Move)); }
public static ProcessingContext Build(ArenaDto arena, IList <BotDto> bots) { return(new ProcessingContext { Arena = arena, Bots = bots }); }
public async Task <ArenaDto> EditArena(ArenaDto arena) { _dbContext.Arenas.Attach(_arenaMapper.Map(arena)); await _dbContext.SaveChangesAsync(); return(_arenaMapper.Map( await _dbContext.Arenas.SingleOrDefaultAsync(x => x.Id == arena.Id))); }
public async Task BotLogic_CreateBot_Should_Create_A_Bot() { // Arrange var randomHelper = new Mock <IRandomHelper>(); var botRepository = new Mock <IRepository <Bot> >(); var scriptRepository = new Mock <IRepository <BotScript> >(); var playerRepository = new Mock <IRepository <Player> >(); var botMapper = new BotMapper(); var botToCreateMapper = new BotToCreateMapper(); var arenaLogic = new Mock <IArenaLogic>(); var configurationHelper = new Mock <IConfigurationHelper>(); IBotLogic botLogic = new BotLogic( randomHelper.Object, botRepository.Object, scriptRepository.Object, playerRepository.Object, botMapper, botToCreateMapper, arenaLogic.Object, configurationHelper.Object); var arenaDto = new ArenaDto(4, 3); var player = new Player { Id = Guid.NewGuid(), LastDeployment = DateTime.MinValue }; var botToCreateDto = new BotToCreateDto(Guid.NewGuid(), "BotName", 100, 200, "BotScript"); var botScripts = new List <BotScript> { new BotScript { Id = Guid.Empty, Script = botToCreateDto.Script } }; // Mock randomHelper.Setup(x => x.Get <PossibleOrientations>()).Returns(PossibleOrientations.South); botRepository.Setup(x => x.Find(Any.Predicate <Bot>(), i => i.Player)).ReturnsAsync(new List <Bot>()); randomHelper.Setup(x => x.Get(It.IsAny <int>())).Returns(5); arenaLogic.Setup(x => x.GetArena()).ReturnsAsync(arenaDto); botRepository.Setup(x => x.Create(It.IsAny <Bot>())).Returns <Bot>(Task.FromResult); playerRepository.Setup(x => x.Single(Any.Predicate <Player>())).ReturnsAsync(player); scriptRepository.Setup(x => x.Single(Any.Predicate <BotScript>())) .ReturnsAsync((Expression <Func <BotScript, bool> > predicate) => botScripts.SingleOrDefault(predicate.Compile())); scriptRepository.Setup(x => x.Update(It.IsAny <BotScript>())).Returns <BotScript>(Task.FromResult); // Act var result = await botLogic.CreateBot(botToCreateDto); // Assert result.Should().NotBeNull(); result.Name.Should().Be(botToCreateDto.Name); result.Orientation.Should().Be(PossibleOrientations.South); result.X.Should().Be(1); result.Y.Should().Be(2); result.FromX.Should().Be(1); result.FromY.Should().Be(2); result.MaximumHealth.Should().Be(botToCreateDto.MaximumHealth); result.CurrentHealth.Should().Be(botToCreateDto.MaximumHealth); result.MaximumStamina.Should().Be(botToCreateDto.MaximumStamina); result.CurrentStamina.Should().Be(botToCreateDto.MaximumStamina); result.Memory.Should().NotBeNull(); result.TimeOfDeath.Should().Be(DateTime.MaxValue); }
public static ProcessingContext Build(ArenaDto arena, IList <BotDto> bots) { return(new ProcessingContext { Arena = arena, Bots = bots, Messages = new List <MessageToCreateDto>() }); }
public async Task Postprocessor_Go_Should_Execute_A_Teleport_Before_A_Regular_Move_And_Thus_Block_Other_Bots_In_Their_Path() { // Arrange var randomHelper = new Mock <IRandomHelper>(); var postprocessor = new Postprocessor(randomHelper.Object); var arena = new ArenaDto { Width = 5, Height = 1 }; var bot1 = new BotDto { Id = Guid.NewGuid(), X = 0, Y = 0, Orientation = PossibleOrientations.East, CurrentStamina = 15, CurrentHealth = 1 }; var bot2 = new BotDto { Id = Guid.NewGuid(), X = 4, Y = 0, Orientation = PossibleOrientations.West, CurrentStamina = 1, CurrentHealth = 1 }; var bots = new List <BotDto>(new[] { bot1, bot2 }); var context = ProcessingContext.Build(arena, bots); var bot1Properties = BotProperties.Build(bot1, arena, bots); var bot2Properties = BotProperties.Build(bot2, arena, bots); bot1Properties.CurrentMove = PossibleMoves.Teleport; bot1Properties.MoveDestinationX = 3; bot1Properties.MoveDestinationY = 0; bot2Properties.CurrentMove = PossibleMoves.WalkForward; context.AddBotProperties(bot1.Id, bot1Properties); context.AddBotProperties(bot2.Id, bot2Properties); // Act await postprocessor.Go(context); // Assert context.Bots.Should().HaveCount(2); context.Bots.Should().ContainEquivalentOf(new BotDto { X = 3, Y = 0, Orientation = PossibleOrientations.East, CurrentStamina = 15 - Constants.STAMINA_ON_TELEPORT, Move = PossibleMoves.Teleport }, c => c.Including(p => p.X) .Including(p => p.Y) .Including(p => p.Orientation) .Including(p => p.CurrentStamina) .Including(p => p.Move)); context.Bots.Should().ContainEquivalentOf(new BotDto { X = 4, Y = 0, Orientation = PossibleOrientations.West, CurrentStamina = 1, Move = PossibleMoves.Idling }, c => c.Including(p => p.X) .Including(p => p.Y) .Including(p => p.Orientation) .Including(p => p.CurrentStamina) .Including(p => p.Move)); }
public async Task Postprocessor_Go_Should_Not_Move_Two_Bots_That_Are_Facing_Each_Other() { // Arrange var randomHelper = new Mock <IRandomHelper>(); var postprocessor = new Postprocessor(randomHelper.Object); var arena = new ArenaDto { Width = 4, Height = 1 }; var bot1 = new BotDto { Id = Guid.NewGuid(), X = 1, Y = 0, Orientation = PossibleOrientations.East, CurrentStamina = 3, CurrentHealth = 1 }; var bot2 = new BotDto { Id = Guid.NewGuid(), X = 2, Y = 0, Orientation = PossibleOrientations.West, CurrentStamina = 4, CurrentHealth = 1 }; var bots = new List <BotDto>(new[] { bot1, bot2 }); var context = ProcessingContext.Build(arena, bots); var bot1Properties = BotProperties.Build(bot1, arena, bots); var bot2Properties = BotProperties.Build(bot2, arena, bots); bot1Properties.CurrentMove = PossibleMoves.WalkForward; bot2Properties.CurrentMove = PossibleMoves.WalkForward; context.AddBotProperties(bot1.Id, bot1Properties); context.AddBotProperties(bot2.Id, bot2Properties); // Act await postprocessor.Go(context); // Assert context.Bots.Should().HaveCount(2); context.Bots.Should().ContainEquivalentOf(new BotDto { X = 1, Y = 0, Orientation = PossibleOrientations.East, CurrentStamina = 3, Move = PossibleMoves.Idling }, c => c.Including(p => p.X) .Including(p => p.Y) .Including(p => p.Orientation) .Including(p => p.CurrentStamina) .Including(p => p.Move)); context.Bots.Should().ContainEquivalentOf(new BotDto { X = 2, Y = 0, Orientation = PossibleOrientations.West, CurrentStamina = 4, Move = PossibleMoves.Idling }, c => c.Including(p => p.X) .Including(p => p.Y) .Including(p => p.Orientation) .Including(p => p.CurrentStamina) .Including(p => p.Move)); }
public void BotProperties_Build_From_Bot_And_Arena_Should_Copy_Properties() { // Arrange var bot = new BotDto { Id = Guid.NewGuid(), X = 1, Y = 2, Orientation = PossibleOrientations.East, Move = PossibleMoves.Teleport, MaximumHealth = 100, CurrentHealth = 99, MaximumStamina = 1000, CurrentStamina = 999, Memory = new Dictionary <String, String>().Serialize() }; var arena = new ArenaDto { Width = 7, Height = 8 }; var bots = new List <BotDto> { new BotDto { Id = Guid.NewGuid(), Name = "BotName", X = 22, Y = 33, Orientation = PossibleOrientations.West } }; // Act var result = BotProperties.Build(bot, arena, bots); // Assert result.Should().NotBeNull(); result.BotId.Should().Be(bot.Id); result.Width.Should().Be(arena.Width); result.Height.Should().Be(arena.Height); result.X.Should().Be(bot.X); result.Y.Should().Be(bot.Y); result.Orientation.Should().Be(bot.Orientation); result.LastMove.Should().Be(bot.Move); result.MaximumHealth.Should().Be(bot.MaximumHealth); result.CurrentHealth.Should().Be(bot.CurrentHealth); result.MaximumStamina.Should().Be(bot.MaximumStamina); result.CurrentStamina.Should().Be(bot.CurrentStamina); result.Memory.Should().BeEquivalentTo(bot.Memory.Deserialize <Dictionary <String, String> >()); result.Messages.Should().BeEquivalentTo(new List <String>()); result.Bots.Should().BeEquivalentTo(bots, p => p .Including(x => x.Id) .Including(x => x.Name) .Including(x => x.X) .Including(x => x.Y) .Including(x => x.Orientation)); result.CurrentMove.Should().Be(PossibleMoves.Idling); }
public async Task <ArenaDto> CreateArena(ArenaDto arena) { arena.Active = true; arena.LastRefreshDateTime = DateTime.UtcNow; var arenaEntity = _arenaMapper.Map(arena); _dbContext.Arenas.Add(arenaEntity); await _dbContext.SaveChangesAsync(); return(_arenaMapper.Map( await _dbContext.Arenas.SingleOrDefaultAsync(x => x.Id == arenaEntity.Id))); }
public void ProcessingContext_Build_Should_Build_A_Valid_ProcessingContext() { // Arrange var arena = new ArenaDto(4, 5); var bots = new List <BotDto>(); // Act var result = ProcessingContext.Build(arena, bots); // Assert result.Should().NotBeNull(); result.Arena.Should().BeSameAs(arena); result.Bots.Should().BeSameAs(bots); }
public async Task Preprocessor_Go_Should_Not_Add_BotProperties_If_No_Bots_Provided() { // Arrange var arena = new ArenaDto(4, 6); var bots = new List <BotDto>(); var processingContext = ProcessingContext.Build(arena, bots); var preprocessor = new Preprocessor(); // Act await preprocessor.Go(processingContext); // Assert processingContext.GetOrderedBotProperties().Should().HaveCount(0); }