public void NavigationService_works() { var plan = new FloorPlan(); plan.FloorTiles.AddRange(_FillArea(20, 10, 1)); plan.GetFloorTile(1, 0).Cost = 3; plan.GetFloorTile(0, 1).Cost = 2; plan.GetFloorTile(1, 1).Cost = 2; plan.GetFloorTile(1, 8).Cost = 3; plan.GetFloorTile(0, 8).Cost = 3; NavigationService service = NSubstitute.Substitute.For <NavigationService>(plan); var path = service.FindPath(new Location(0, 0), new Location(14, 8)); Debug.Write(plan.Print(path)); }
public void Agents_attack_tiles() { RoomService roomService = NSubstitute.Substitute.For <RoomService>(); var plan = new FloorPlan(3, 3, fill: true); var agent = new Agent(); //NSubstitute.Substitute.For<Agent>(); agent.Move(new Location(1, 1)); plan.AddAgent("Test Agent", agent); var tile = plan.GetFloorTile(2, 2); agent.AttackTile(tile).Should().BeFalse(); tile = plan.GetFloorTile(1, 2); tile.Cost = 2; agent.AttackTile(tile).Should().BeTrue(); tile.Cost.Should().Be(1); agent.AttackTile(tile).Should().BeFalse(); tile.Cost.Should().Be(1); }
public void Refresh(FloorPlan floorPlan) { FloorPlan = floorPlan; MaxRow = floorPlan.FloorTiles.Max(x => x.Y); MaxCol = floorPlan.FloorTiles.Max(x => x.X); Weight = new decimal[MaxCol + 1, MaxRow + 1]; for (int row = 0; row <= MaxRow; row++) { for (int col = 0; col <= MaxCol; col++) { var tile = floorPlan.GetFloorTile(col, row); Weight[col, row] = tile?.Cost ?? 0; } } }
public void FloorPlan_detects_tiles() { FloorPlan plan = NSubstitute.Substitute.For <FloorPlan>(); plan.GetFloorTile(10, 1).Should().BeNull(); plan.FloorTiles.AddRange(_FillArea(30, 10, 1)); plan.GetFloorTile(20, 1).Cost.Value.ShouldBeEquivalentTo(1); plan.GetFloorTile(10, 2).Cost = 5; plan.GetFloorTile(10, 2).Cost.Value.ShouldBeEquivalentTo(5); plan.GetFloorTile(30, 0).Should().BeNull(); plan.GetFloorTile(0, 10).Should().BeNull(); }
public void FloorPlan_detects_adjacent_tiles() { FloorPlan plan = NSubstitute.Substitute.For <FloorPlan>(); plan.FloorTiles.AddRange(_FillArea(5, 5)); var center = plan.GetFloorTile(2, 2); plan.GetNorth(center).Should().BeSameAs(plan.GetFloorTile(2, 1)); plan.GetSouth(center).Should().BeSameAs(plan.GetFloorTile(2, 3)); plan.GetWest(center).Should().BeSameAs(plan.GetFloorTile(1, 2)); plan.GetEast(center).Should().BeSameAs(plan.GetFloorTile(3, 2)); plan.GetNorth(center).Should().NotBeSameAs(plan.GetFloorTile(2, 3)); var corner = plan.GetFloorTile(0, 0); plan.GetNorth(corner).Should().BeNull(); plan.GetSouth(corner).Should().BeSameAs(plan.GetFloorTile(0, 1)); plan.GetWest(corner).Should().BeNull(); plan.GetEast(corner).Should().BeSameAs(plan.GetFloorTile(1, 0)); corner = plan.GetFloorTile(4, 4); plan.GetNorth(corner).Should().BeSameAs(plan.GetFloorTile(4, 3)); plan.GetSouth(corner).Should().BeNull(); plan.GetWest(corner).Should().BeSameAs(plan.GetFloorTile(3, 4)); plan.GetEast(corner).Should().BeNull(); }