public async Task UpdateAsync(Droid droid) { using (var connection = _connectionProvider()) { await ExecuteUpdateAsync(droid, connection); } }
private static async Task <int> ExecuteUpdateAsync(Droid droid, IDbConnection connection) { return(await connection.ExecuteAsync( DroidStoredProcedures.UpdateDroid, droid.ToDto(), commandType : CommandType.StoredProcedure)); }
public async Task <int> Add(Droid droid) { _db.Droids.Add(droid); await _db.SaveChangesAsync(); return(droid.Id); }
public void UpdateViewFromNewDroid(Droid droid) { SetDroidTypeText(droid); SetDroidDeployTimeText(droid); SetDroidHealthText(droid); SetDroidEnergyText(droid); }
public async void ReturnR2D2DroidGivenIdOf1() { Droid droid = await _droidRepository.Get(1); Assert.NotNull(droid); Assert.Equal("R2-D2", droid.Name); }
private void Load() { if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path, FileMode.Open); PlayerData data = (PlayerData)bf.Deserialize(file); file.Close(); xp = data.Xp; requiredXp = data.RequiredXp; levelBase = data.LevelBase; lvl = data.Lvl; foreach (DroidData droidData in data.Droids) { Droid droid = new Droid(); droid.LoadDroidData(droidData); AddDroid(droid.gameObject); } } else { InitLevelData(); } }
public async void AddNewDroid() { // Given var droid2101 = new Droid { Id = 2101, Name = "Droid2101", PrimaryFunction = "Function2101" }; // When _characterRepository.Add(droid2101); var saved = await _characterRepository.SaveChangesAsync(); // Then Assert.True(saved); using (var db = new AmstramgramContext(_options, _dbLogger.Object)) { var character = await db.Characters.FindAsync(2101); Assert.NotNull(character); Assert.IsType <Droid>(character); Assert.Equal(2101, character.Id); Assert.Equal("Droid2101", character.Name); // Cleanup db.Characters.Remove(character); await db.SaveChangesAsync(); } }
public void KillDroid(Droid droid) { activeDroidCount--; Droidpool.Add(droid); ActiveDroidPool.Remove(droid); }
/// <summary> /// Creates a board state for the current turn /// </summary> /// <param name="droids"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="playerID"></param> public BoardState(Droid[] droids, Tile[] tiles, int width, int height, int playerID) { mapWidth = width; mapHeight = height; ourID = playerID; update(droids, tiles); }
public async Task CreateDroid_WithDroidSet_DroidCreatedSuccessfully() { // Arrange var newDroidId = new Guid("c29a188b-a562-47b4-a74c-9e82702e0986"); var droidDto = new DroidDto { DroidId = newDroidId, CreationDate = DateTimeOffset.Now, Name = "Dada", Nickname = "Da", Quote = "Votre manque de foi me consterne. - Dark Vador" }; var armDtoList = new List <IArmDto> { new ArmDto { DroidId = newDroidId, ArmId = Guid.NewGuid() } }; var droid = Droid.FromDto(droidDto).WithArms(armDtoList); // Act await _repo.InsertAsync(droid); var droidSelected = await _repo.GetBySerialNumberAsync(newDroidId, Droid.AssertExists); // Assert droidSelected.DroidId.Should().Be(Guid.Parse("c29a188b-a562-47b4-a74c-9e82702e0986")); droidSelected.Name.Should().Be("Dada"); droidSelected.Nickname.Should().Be("Da"); droidSelected.Quote.Should().Be("Votre manque de foi me consterne. - Dark Vador"); }
public async Task UpdateDroid_WithValidNameAndNickname_DroidUpdatedSuccessfully() { // Arrange var droidDto = new DroidDto { DroidId = _existingDroidId, CreationDate = DateTimeOffset.Now, Name = "Didi", Nickname = "Di", }; var armDtoList = new List <IArmDto> { new ArmDto { DroidId = _existingDroidId, ArmId = Guid.NewGuid() } }; var droid = Droid.FromDto(droidDto).WithArms(armDtoList); // Act await _repo.UpdateAsync(droid); var droidSelected = await _repo.GetBySerialNumberAsync(_existingDroidId, Droid.AssertExists); // Assert droidSelected.Name.Should().Be("Didi"); droidSelected.Nickname.Should().Be("Di"); }
public bool SetDroid(Droid droid) { if (_currentDroid == null) { if (droid != null) { _currentDroid = droid; _droidBayView.GetDroidImage().sprite = droid.GetDroidModel().GetDroidView().GetDroidSprite(); _droidBayView.EnableDroidImage(); _currentDroid.GetDroidModel().SetCurrentDroidBay(GetDroidManager().GetDroidManagerModel().GetDroidBay(_bayIndex)); _droidBayView.UpdateViewFromNewDroid(_currentDroid); } return(true); } else if (_currentDroid != null && droid == null) { _currentDroid = null; _droidBayView.CleanBay(); } return(false); }
public async void AddNewDroid() { // Given var droid2101 = new Droid { Id = 2101, Name = "Droid2101", PrimaryFunction = "Function2101" }; // When _droidRepository.Add(droid2101); var saved = await _droidRepository.SaveChangesAsync(); // Then Assert.True(saved); using (var db = new StarWarsContext(_options, _dbLogger.Object)) { var droid = await db.Droids.FindAsync(2101); Assert.NotNull(droid); Assert.Equal(2101, droid.Id); Assert.Equal("Droid2101", droid.Name); // Cleanup db.Droids.Remove(droid); await db.SaveChangesAsync(); } }
public async void DeleteExistingDroid() { // Given using (var db = new StarWarsContext(_options, _dbLogger.Object)) { var droid2100 = new Droid { Id = 2100, Name = "Droid2100", PrimaryFunction = "Function2100" }; await db.Droids.AddAsync(droid2100); await db.SaveChangesAsync(); } // When _droidRepository.Delete(2100); var saved = await _droidRepository.SaveChangesAsync(); // Then Assert.True(saved); using (var db = new StarWarsContext(_options, _dbLogger.Object)) { var deletedDroid = await db.Droids.FindAsync(2100); Assert.Null(deletedDroid); } }
public IActionResult Post([FromBody] Droid droid) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(new Error.Repository.Error { HttpCode = 400, Message = $"Invalid payload: {ModelState}" })); } var result = droidRepo.Put(droid); if (!result) { return(new BadRequestObjectResult(new Error.Repository.Error { HttpCode = 409, Message = $"Droid with name: '{droid.Name}' already exists" })); } //return new CreatedAtRouteResult("GetDroidById", new { id = droid.Id }, droid); return(new CreatedAtRouteResult(new { Controller = "droids", Action = nameof(GetById), id = droid.Id }, droid)); }
public IActionResult Post([FromBody] Droid droid) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(new Error { HttpCode = 400, Message = $"Invalid payload: {ModelState}" })); } var result = droidRepo.Put(droid); if (!result) { return(new BadRequestObjectResult(new Error { HttpCode = 409, Message = $"Droid with name: '{droid.Name}' already exists" })); } return(new CreatedAtRouteResult(new { controller = "Droids", model = droid.Name }, droid)); }
public bool Create(Droid newDroid) { var droid = new Model.Droid(newDroid); newDroid.Id = id++; repo.TryAdd(newDroid.Id, new Model.Droid(newDroid)); return(true); }
protected override void SolvePartOne() { var droid = new Droid(program); var shipGraph = ExploreAndTakeItems(droid); MoveDroidToSecurityCheckpoint(droid, shipGraph); resultPartOne = BreachSecurity(droid, shipGraph); }
private void MoveDroidToSecurityCheckpoint(Droid droid, ShipGraph shipGraph) { var(path, _) = GraphSearch.Dijkstra(shipGraph, droid.Room, "== Security Checkpoint =="); foreach (var nextRoom in path) { droid.TakeDoor((Direction)shipGraph.GetDoorDirection(droid.Room, nextRoom)); } }
public async Task CreateDroid_WithNameAlreadyExists_ReturnsDroidConflictNameExceptionAsync() { // Arrange var exception = await Record.ExceptionAsync(() => Droid.CreateNewAsync(_nameAlreadyExists, _starWarsQuote, _encrypt.Encrypt, _createDroid)).ConfigureAwait(false); // Assert exception.Should().BeOfType <DroidConflictNameException>(); }
public Droid Get(int id) { Droid result = null; result = DroidRepository.Results.FirstOrDefault(x => x.Id == id); return(result); }
public Mission(MissionTypes missionType, Droid agent, Func<Point, bool> target, Func<Point, bool> isWalkable, Func<Point, bool> attackAlongTheWay) { this.missionType = missionType; this.agent = agent; this.target = target; this.isWalkable = isWalkable; this.attackAlongTheWay = attackAlongTheWay; }
public XYZObject() { var dataSourceManager = DataManager.DataSourceManager; _structuredArchiveDataSource = XYZOjectDataSourceFactory.Get(dataSourceManager); // _droid = _structuredArchiveDataSource.GenerateDroid(); _structuredArchiveDataSource.AddItem(_droid, this); }
public DroidData(Droid droid) { spawnRate = droid.SpawnRate; catchRate = droid.CatchRate; attack = droid.Attack; defense = droid.Defense; hp = droid.Hp; crySound = droid.CrySound.name; }
private ShipGraph ExploreAndTakeItems(Droid droid) { var shipGraph = new ShipGraph(); shipGraph.AddRoom(droid); var unexploredRooms = new HashSet <string> { droid.Room }; var path = new List <Direction>(); while (unexploredRooms.Any()) { var lastRoom = droid.Room; if (unexploredRooms.Contains(droid.Room)) { droid.TakeItems(droid.FloorItems.Except(blacklistItems)); foreach (var door in shipGraph.GetUnexploredDoorsOf(droid.Room)) { droid.TakeDoor(door); if (droid.Room != lastRoom) { if (!shipGraph.ContainsNode(droid.Room)) { shipGraph.AddRoom(droid); unexploredRooms.Add(droid.Room); } shipGraph.AddDoorKnowledge(lastRoom, droid.Room, door); droid.TakeDoor(door.Opposite()); } } unexploredRooms.Remove(lastRoom); } else { var neighbours = shipGraph.Neighbours(droid.Room).Select(node => node.nb); var unexploredNextToCurrent = unexploredRooms.Intersect(neighbours); Direction door; if (unexploredNextToCurrent.Any()) { var nextRoom = unexploredNextToCurrent.First(); var direction = shipGraph.GetDoorDirection(droid.Room, nextRoom); door = (Direction)direction; path.Add(door); } else { door = path.Last().Opposite(); path.RemoveAt(path.Count - 1); } droid.TakeDoor(door); } } return(shipGraph); }
static void CreateDots(Droid d) { var numDots = d.GetFeelerCount(); for (var i = 0; i < numDots; i++) { GameObject.Instantiate(d.DotPrefab, d.transform.parent); } }
public bool AddDroidToBay(Droid droid) { if (!_droidBayModel.SetDroid(droid)) { return(false); } return(true); }
public void LoadDroid_WithFromNullDto_ReturnsDroidNotFoundExceptionAsync() { // Arrange IDroidDto droid = null; // Assert var exception = Record.Exception(() => Droid.FromDto(droid)); exception.Should().BeOfType <DroidNotFoundException>(); }
public async Task AddArmDroid_ArmCreatedSuccessfullyAsync() { // Act var droid = await Droid.CreateNewAsync(_nameNotAlreadyExists, _starWarsQuote, _encrypt.Encrypt, _createDroid).ConfigureAwait(false); droid.AddArm(); // Assert droid.Arms.Should().HaveCount(1); }
public void UpgradeDroid() { if (_droidBayModel.GetDroid() == null) { Droid newDroid = DroidFactory.instance.CreateDroid(DroidType.SearchDroid); newDroid.GetDroidModel().SetCurrentDroidBay(this); AddDroidToBay(newDroid); } }
static void Main15(string[] args) { string inputProgram = File.ReadAllText(@".\Day15\input.txt"); long[] instructionSet = inputProgram.Trim('\n').Split(',').Select((instr) => Int64.Parse(instr)).ToArray(); LargeMemSet memSet = new LargeMemSet(instructionSet); var droid = new Droid(); ComputeIntCode(memSet, droid); }
public Droid Update(Droid droid) { if (repo.ContainsKey(droid.Id)) { droid.Id = repo[droid.Id].Id; repo[droid.Id] = new Model.Droid(droid); return(droid); } return(null); }
/// <summary> /// Returns a bitboard with the specified unit of the specified player set to 1 /// everything else is set to 0 /// </summary> /// <param name="droids"></param> /// <param name="playerID"></param> /// <param name="droidType"></param> public void setAllDroidsForPlayer(Droid[] droids, int playerID, int droidType) { clear(); for (int i = 0; i < droids.Length; i++) { if (droids[i].Owner == playerID) { setValueAtSpot(droids[i].X, droids[i].Y); } } }
/// <summary> /// Synchronizes with the server, then calls run(). /// </summary> /// <returns> /// Return true to end turn, false to resynchronize with the /// server and run again. /// </returns> public bool startTurn() { int count = 0; iteration++; count = Client.getPlayerCount(connection); players = new Player[count]; for(int i = 0; i < count; i++) players[i] = new Player(Client.getPlayer(connection, i)); count = Client.getMappableCount(connection); mappables = new Mappable[count]; for(int i = 0; i < count; i++) mappables[i] = new Mappable(Client.getMappable(connection, i)); count = Client.getDroidCount(connection); droids = new Droid[count]; for(int i = 0; i < count; i++) droids[i] = new Droid(Client.getDroid(connection, i)); count = Client.getTileCount(connection); tiles = new Tile[count]; for(int i = 0; i < count; i++) tiles[i] = new Tile(Client.getTile(connection, i)); count = Client.getModelVariantCount(connection); modelVariants = new ModelVariant[count]; for(int i = 0; i < count; i++) modelVariants[i] = new ModelVariant(Client.getModelVariant(connection, i)); if(!initialized) { initialized = true; init(); } return run(); }
public static void TryOperate(Droid droid) { if (droid.AttacksLeft > 0) { foreach (var p in droid.ToPoint().GetPointsInRange(droid.Range)) { Droid target; if (Bb.DroidLookup.TryGetValue(p, out target)) { if (droid.IsOperatable(target)) { while(droid.AttacksLeft > 0) { droid.operate(target.X, target.Y); } } } } } }
public void TryAttack(Droid attacker) { if (attacker.AttacksLeft > 0) { var targetsInRange = attacker.ToPoint().GetPointsInRange(attacker.Range).Where(p => Targets.Contains(p)); if (targetsInRange.Any()) { var target = targetsInRange.First(); while (attacker.AttacksLeft > 0) { attacker.operate(target.x, target.y); } } } }
public static void Init() { using (var db = new EfContext()) { if (db.Accounts.Any()) return; var account = new Account { Name = "My Test Account", Paid = true, PaidUtc = new DateTime(2016, 1, 1), }; db.Accounts.Add(account); var user = new User { Name = "Joe User", Account = account, Active = true, }; db.Users.Add(user); var account2 = new Account { Name = "Another Test Account", Paid = false, }; db.Accounts.Add(account2); var user2 = new User { Name = "Late Paying User", Account = account2 }; db.Users.Add(user2); db.MutateMes.Add(new MutateMe()); var human = new Human { Id = 1, Name = "Han Solo", Height = 5.6430448 }; db.Heros.Add(human); var stormtrooper = new Stormtrooper { Id = 2, Name = "FN-2187", Height = 4.9, Specialization = "Imperial Snowtrooper" }; db.Heros.Add(stormtrooper); var droid = new Droid { Id = 3, Name = "R2-D2", PrimaryFunction = "Astromech" }; db.Heros.Add(droid); var vehicle = new Vehicle { Id = 1, Name = "Millennium falcon", Human = human }; db.Vehicles.Add(vehicle); var vehicle2 = new Vehicle { Id = 2, Name = "Speeder bike", Human = stormtrooper }; db.Vehicles.Add(vehicle2); db.SaveChanges(); } }
// Choose and remove all but your favorite target from your choice private Solver.DroidTurn ChooseTurn(Droid droid, IEnumerable<Solver.DroidTurn> turns) { return turns.MaxBy(t => t.Steps.Count()); }
private Property PropertyDroidDrop(Droid droidOfProperty, PresentationBox presboxToPutPropertyIn) { Property prop = DataManager.Resolve(droidOfProperty) as Property; if (prop!=null) { presboxToPutPropertyIn.Text = prop.Name; } return prop; }
public DroidMovement(Droid droid) { this.droid = droid; }
public AIDroidMovement(Droid droid) : base(droid) { }
/// <summary> /// Update the position of all droids /// </summary> /// <param name="droids"></param> public void update(Droid[] droids, Tile[] tiles) { ourHangers = new Bb(mapWidth, mapHeight); theirHangers = new Bb(mapWidth, mapHeight); ourMovables = new Bb(mapWidth, mapHeight); theirMovables = new Bb(mapWidth, mapHeight); ourImmovables = new Bb(mapWidth, mapHeight); theirImmovables = new Bb(mapWidth, mapHeight); notAttackedByEnemy = new Bb(mapWidth, mapHeight); walkable = new Bb(mapWidth, mapHeight); attackTargets = new Bb(mapWidth, mapHeight); hackTargets = new Bb(mapWidth, mapHeight); ourHalf = new Bb(mapWidth, mapHeight); theirHalf = new Bb(mapWidth, mapHeight); ourUnitsLowArmor = new Bb(mapWidth, mapHeight); for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { if (i < 20) { ourHalf.setValueAtSpot(i, j); } else { theirHalf.setValueAtSpot(i, j); } } } if (ourID == 1) { ourHalf.board = ourHalf.board.Not(); theirHalf.board = theirHalf.board.Not(); } for (int i = 0; i < droids.Length; i++) { Droid current = droids[i]; switch (current.Variant) { case (int)Unit.CLAW: case (int)Unit.ARCHER: case (int)Unit.REPAIRER: case (int)Unit.HACKER: case (int)Unit.TERMINATOR: if (current.HealthLeft > 0) { if (current.Owner == ourID) { ourMovables.setValueAtSpot(current.X, current.Y); if (current.HackedTurnsLeft > 0) { attackTargets.setValueAtSpot(current.X, current.Y); hackTargets.setValueAtSpot(current.X, current.Y); } else if(current.Armor < current.MaxArmor) { ourUnitsLowArmor.setValueAtSpot(current.X, current.Y); } } else { theirMovables.setValueAtSpot(current.X, current.Y); if (current.HackedTurnsLeft <= 0) { attackTargets.setValueAtSpot(current.X, current.Y); hackTargets.setValueAtSpot(current.X, current.Y); } } } break; case (int)Unit.TURRET: case (int)Unit.WALL: if (current.HealthLeft > 0) { if (current.Owner == ourID) ourImmovables.setValueAtSpot(current.X, current.Y); else { theirImmovables.setValueAtSpot(current.X, current.Y); attackTargets.setValueAtSpot(current.X, current.Y); } } break; case (int)Unit.HANGAR: if (current.HealthLeft > 0) { if (current.Owner == ourID) ourHangers.setValueAtSpot(current.X, current.Y); else { theirHangers.setValueAtSpot(current.X, current.Y); attackTargets.setValueAtSpot(current.X, current.Y); } } break; } if (current.Owner != ourID) { Queue<Point> frontier = new Queue<Point>(); HashSet<Point> explored = new HashSet<Point>(); frontier.Enqueue(new Point(current.X, current.Y)); explored.Add(new Point(current.X, current.Y)); int depth = 0; while (frontier.Count > 0 && depth < current.MaxMovement + current.Range) { depth++; Point point = frontier.Dequeue(); for (int j = -1; j < 2; j += 2) { Point pX = new Point(point.X + j, point.Y); if (pX.X >= 0 && pX.X < mapWidth) { if (!explored.Contains(pX)) { explored.Add(pX); frontier.Enqueue(new Point(pX.X, pX.Y)); notAttackedByEnemy.setValueAtSpot(pX.X, pX.Y); } } Point pY = new Point(point.X, point.Y + j); if (pY.Y >= 0 && pY.Y < mapHeight) { if (!explored.Contains(pY)) { explored.Add(pY); frontier.Enqueue(new Point(pY.X, pY.Y)); notAttackedByEnemy.setValueAtSpot(pY.X, pY.Y); } } } } } } notAttackedByEnemy.board.Not(); walkable.board.Or(ourHangers.board).Or(theirHangers.board).Or(ourMovables.board).Or(theirMovables.board).Or(ourImmovables.board).Or(theirImmovables.board); foreach (Tile t in tiles) { if (t.TurnsUntilAssembled == 1) { walkable.setValueAtSpot(t.X, t.Y); } } walkable.board.Not(); }
public void Apply(Droid attacker) { foreach (var step in Steps) { TryAttack(attacker); attacker.move(step.x, step.y); } TryAttack(attacker); }
public static void MoveAndAttack(Droid droid, IEnumerable<Point> path) { var targetPoint = path.Last(); foreach (var point in path) { if (droid.MovementLeft == 0 || droid.IsInRange(targetPoint)) { break; } droid.move(point.x, point.y); } if (droid.IsInRange(targetPoint)) { droid.operate(targetPoint.x, targetPoint.y); var target = Bb.DroidLookup[targetPoint]; if ((Unit)target.Variant == Unit.HANGAR && target.HealthLeft <= 0) { Bb.KillHangerCountDown = 0; // Todo, release the kittens } } }
public static void MoveAndAttack(Droid attacker, BitArray targets) { Bb.ReadBoard(); if (attacker.AttacksLeft <= 0) { return; } BitArray validTargets; if ((Unit)attacker.Variant == Unit.HACKER) { validTargets = targets.ToPoints().Where(t => t.IsHackable()).ToBitArray(); } else if ((Unit)attacker.Variant == Unit.REPAIRER) { validTargets = targets.ToPoints().Where(t => t.IsRepairable()).ToBitArray(); } else { validTargets = targets.ToPoints().Where(t => t.IsAttackable()).ToBitArray(); if (Bb.KillHangerCountDown > 0) { validTargets = validTargets.ToPoints().Where(t => { var droid = Bb.DroidLookup[t]; return !((Unit)droid.Variant == Unit.HANGAR && droid.HealthLeft <= attacker.Attack); }).ToBitArray(); } } Func<Point, bool> patherPassable = p => IsPassable(p) || p.Equals(attacker.ToPoint()) || validTargets.Get(p); var path = Pather.AStar(new[] { attacker.ToPoint() }, patherPassable, validTargets.ToFunc()); if (path == null) { return; } if (path.Count() < 2) { Console.WriteLine("Bad path from attacker " + attacker.Id); } MoveAndAttack(attacker, path.Skip(1)); }
public PlayerDroidMovement(Droid droid) : base(droid) { }
public static void MoveFarthestAndAttack(Droid attacker, BitArray targets) { if (attacker.AttacksLeft == 0) { return; } var liveTargets = targets.ToPoints().Where(p => Bb.DroidLookup[p].HealthLeft > 0); Func<Point, bool> patherPassable = p => IsPassable(p) || p.Equals(attacker.ToPoint()); var movementSearch = new Pather.Search(new Point[] { attacker.ToPoint() }, patherPassable, p => false, (p1, p2) => 1, attacker.MovementLeft); var walkables = movementSearch.GScore.Keys.Where(p => movementSearch.GScore[p] <= attacker.MovementLeft); var walkablesWithTargets = walkables.Where(p => liveTargets.Any(t => p.IsInRange(attacker.Range, t))); Console.WriteLine("MoveFarthestAndAttack " + attacker.ToPoint()); Console.WriteLine("Walkables: " + walkables.Count()); Console.WriteLine("WalkablesWithTargets: " + walkablesWithTargets.Count()); if (walkablesWithTargets.Any()) { var walkTo = walkablesWithTargets.MaxBy(p => movementSearch.GScore[p]); var path = Pather.ConstructPath(movementSearch.CameFrom, walkTo); foreach (var step in path.Skip(1)) { Console.WriteLine("Move {0} -> {1}", attacker.ToPoint(), step); attacker.move(step.x, step.y); } var target = liveTargets.First(t => attacker.IsInRange(t)); attacker.operate(target.x, target.y); } }