public static SeedGrowth Create(int domainWidth, int domainHeight, Neighbourhood neighbourhoodType, BoundaryConditions boundaryConditionsType) { SeedGrowth sd = new SeedGrowth(domainWidth, domainHeight); sd.setNeighbourhoodType(getNeigbhourhoodType(neighbourhoodType, boundaryConditionsType)); return(sd); }
public Controller() { this.civilPlayers = new List <IPlayer>(); this.guns = new GunRepository(); this.mainPlayer = new MainPlayer(); this.neighbourhood = new Neighbourhood(); }
private AutomataDefinition(Neighbourhood neighbourhood, bool wrap, StateDefinition[] states) { NumStates = states.Length; Neighbourhood = neighbourhood; Wrap = wrap; States = states; }
private void ResultsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (resultsListBox.SelectedItem == null) { return; } if (districtComboBox.SelectedItem == null || searchType == SearchType.District) { District district = (District)resultsListBox.SelectedItem; districtComboBox.SelectedItem = district; if (searchType != SearchType.District) { resultsListBox.ItemsSource = district.GetNeighbourhoods(); } } else if (neighbourComboBox.SelectedItem == null || searchType == SearchType.Neighbourhood) { Neighbourhood neighbourhood = (Neighbourhood)resultsListBox.SelectedItem; neighbourComboBox.SelectedItem = neighbourhood; if (searchType == SearchType.Property) { resultsListBox.ItemsSource = neighbourhood.GetProperties(); } } else if (propertyComboBox.SelectedItem == null && searchType == SearchType.Property) { propertyComboBox.SelectedItem = (Property)resultsListBox.SelectedItem; } }
public async Task <IHttpActionResult> PutNeighbourhood(int id, Neighbourhood neighbourhood) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != neighbourhood.NeighbourhoodID) { return(BadRequest()); } db.Entry(neighbourhood).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NeighbourhoodExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public override bool[,] Iterate() { int width = Grid.Width; int height = Grid.Width; bool[,] newGrid = new bool[width, height]; for (short y = 0; y < height; y++) { for (short x = 0; x < width; x++) { Neighbourhood n = new Neighbourhood(Grid.Content, x, y, 2); bool active = (n.Neighbours[4] && n.Neighbours[5] && !(n.Neighbours[0] || n.Neighbours[1] || n.Neighbours[2] || n.Neighbours[6] || n.Neighbours[7] || n.Neighbours[8])) || (n.Neighbours[3] && n.Neighbours[4] && !(n.Neighbours[0] || n.Neighbours[1] || n.Neighbours[5] || n.Neighbours[6] || n.Neighbours[7] || n.Neighbours[8])) || (n.Neighbours[2] && n.Neighbours[7] && !(n.Neighbours[0] || n.Neighbours[1] || n.Neighbours[3] || n.Neighbours[4] || n.Neighbours[5] || n.Neighbours[6] || n.Neighbours[8])) || (n.Neighbours[3] && n.Neighbours[8] && !(n.Neighbours[0] || n.Neighbours[1] || n.Neighbours[2] || n.Neighbours[4] || n.Neighbours[5] || n.Neighbours[6] || n.Neighbours[7])); newGrid[x, y] = active; } } Grid.Content = newGrid; return(Grid.Content); }
public async Task <Neighbourhood> CreateNeighbourhoodAsync(Neighbourhood neighbourhood) { _context.Add(neighbourhood); await _context.SaveChangesAsync(); return(neighbourhood); }
public ActionResult DeleteConfirmed(int id) { Neighbourhood neighbourhood = db.Neighbourhoods.Find(id); db.Neighbourhoods.Remove(neighbourhood); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Location location) { if (!ModelState.IsValid) { ViewBag.CategoryId = new SelectList(this.Context.Categories .Where(c => c.Name != null) .OrderBy(c => c.Name), "Id", "Name", location.ShoppingCenter.CategoryId); return(View(location)); } var neighbourhood = this.Context.Neighbourhoods.FirstOrDefault(n => n.Name == location.Neighbourhood.Name); if (neighbourhood == null) { var sofia = this.Context.Cities.FirstOrDefault(c => c.Name == "Sofia"); neighbourhood = new Neighbourhood { City = sofia, Name = location.Neighbourhood.Name }; } var newLocation = new Location { FullAddress = location.FullAddress, IsApproved = false, Latitude = location.Latitude, Longitude = location.Longitude, Neighbourhood = neighbourhood, PlaceId = location.PlaceId, ShoppingCenter = new ShoppingCenter { CategoryId = location.ShoppingCenter.Category.Id, Details = location.ShoppingCenter.Details, WorkTime = location.ShoppingCenter.WorkTime } }; if (User.IsInRole(UserRoles.Moderator) || User.IsInRole(UserRoles.Admin)) { newLocation.IsApproved = true; } string msg = "New location successfuly added!"; if (newLocation.IsApproved == false) { msg += "\r\nThe location needs to be approved by Moderator before it can be visible for everyone."; } this.CurrentUser.Locations.Add(newLocation); this.Context.SaveChanges(); return(this.RedirectWithSuccess("Locations", "Index", msg)); }
public Street(string name, Neighbourhood neighbourhood, int row, int column, int price) : base(name, neighbourhood.Color, row, column) { this.Price = price; neighbourhood.Streets.Add(this); this.Neighbourhood = neighbourhood; this.IsDamaged = false; this.IsProtected = false; }
private static bool _ParseNeighbourhoodMove(string[] commandParts, Neighbourhood neighbourhood) { string familyName = commandParts[1]; string plotName = commandParts[2]; neighbourhood.Move(familyName, plotName); // only return false when command not recognised. return(true); }
public void WhenAlive_ShouldBecomeDead_WhenLessThan2NeighboursAreAlive() { var cell = new Cell(CellState.Alive); Neighbourhood neighbourhood = NeighbourhoodFactory.MakeNeighbourhood(1); cell.Transition(neighbourhood); Assert.False(cell.IsAlive()); }
public static Neighbourhood WithHouses(this Neighbourhood neighbourhood, params House[] houses) { foreach (var house in houses) { neighbourhood.AddHouse(house); } return(neighbourhood); }
public void WhenDead_ShouldBecomeAlive_WhenExactly3NeighboursAreAlive() { var cell = new Cell(); Neighbourhood neighbourhood = NeighbourhoodFactory.MakeNeighbourhood(3); cell.Transition(neighbourhood); Assert.True(cell.IsAlive()); }
public void WhenDead_ShouldRemainDead_WhenAliveNeighboursAreMoreThan3() { var cell = new Cell(); Neighbourhood neighbourhood = NeighbourhoodFactory.MakeNeighbourhood(4); cell.Transition(neighbourhood); Assert.False(cell.IsAlive()); }
/// <summary> /// Maps distance to seeds in a specified region /// </summary> /// <param name="filter">Region specification</param> /// <param name="seeds">Coordinate for seeding distance measures</param> /// <param name="neighbourhood">Neighbourhood type</param> /// <returns>2D int array of distance to seed</returns> public static int[,] Distance(this bool[,] filter, Coordinate[] seeds, Neighbourhood neighbourhood = Neighbourhood.Cross) { bool[,] seed = new bool[filter.GetLength(0), filter.GetLength(1)]; for (int i = 0, l = seeds.Length; i < l; i++) { seed[seeds[i].x, seeds[i].y] = true; } return(filter.Distance(seed, neighbourhood)); }
public async Task <IActionResult> Create([Bind("NeighbourhoodGroup,Neighbourhood1")] Neighbourhood neighbourhood) { if (ModelState.IsValid) { _context.Add(neighbourhood); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(neighbourhood)); }
public ActionResult Edit([Bind(Include = "NeighbourhoodId,NeighbourhoodName,DistrictId")] Neighbourhood neighbourhood) { if (ModelState.IsValid) { db.Entry(neighbourhood).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DistrictId = new SelectList(db.Districts, "DistrictId", "DistrictName", neighbourhood.DistrictId); return(View(neighbourhood)); }
public ActionResult Create([Bind(Include = "NeighbourhoodId,NeighbourhoodName,DistrictId")] Neighbourhood neighbourhood) { if (ModelState.IsValid) { db.Neighbourhoods.Add(neighbourhood); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DistrictId = new SelectList(db.Districts, "DistrictId", "DistrictName", neighbourhood.DistrictId); return(View(neighbourhood)); }
public async Task <IHttpActionResult> PostNeighbourhood(Neighbourhood neighbourhood) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Neighbourhoods.Add(neighbourhood); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = neighbourhood.NeighbourhoodID }, neighbourhood)); }
private static void _ParseNeighbourhood(string command) { Neighbourhood neighbourhood = SceneManager.currentScene as Neighbourhood; if (neighbourhood == null) { Debug.Error("Current scene is not Neighbourhood but trying to parse command"); return; } string[] commandParts = command.Split(" "); string directive = commandParts[0].ToLower(); try { // Yes this nested if structure isn't particularly neat. Oh well // edit: solution is to delegate to smaller functions. Then can return in the smaller functions // without having to use goto statement if (directive.Equals("new")) { if (_ParseNeighbourhoodNew(commandParts, neighbourhood)) { return; } } else if (directive.Equals("move")) { if (_ParseNeighbourhoodMove(commandParts, neighbourhood)) { return; } } else if (directive.Equals("play")) { // TODO } else if (directive.Equals("info")) { if (_ParseNeighbourhoodInfo(commandParts, neighbourhood)) { return; } } } catch (IndexOutOfRangeException exception) { Debug.Log(exception.ToString()); goto End; } End: Game.PrintLn($"'{command}' is not a recognised command in Neighbourhood Mode. Enter 'help' for more."); }
void CalculateNextStepStandard(int startX, int startY, int endX, int endY) { Random r = new Random(); nextStepGrid.Copy(currentGrid, startX, startY, endX, endY); List <Point> n; List <int> a = new List <int>(); for (int x = startX; x < endX; x++) { for (int y = startY; y < endY; y++) { if (currentGrid.Cells[x, y].State != 0) { continue; } n = Neighbourhood.GetNeighborhood(x, y, Grid.SizeX, Grid.SizeY, BoundaryCondition); a.Clear(); n.FindAll(p => currentGrid.Cells[p.X, p.Y].State == 1).ForEach(p => a.Add(currentGrid.Cells[p.X, p.Y].Id)); Dictionary <int, int> counts = a.GroupBy(v => v) .ToDictionary(g => g.Key, g => g.Count()); int max = 0; int k = 0; foreach (int key in counts.Keys) { if (max < counts[key]) { max = counts[key]; k = key; } else if (max == counts[key] && r.NextDouble() > 0.5) { k = key; } } if (max > 0) { lock (synLock) { emptyCount--; nextStepGrid.Cells[x, y].ChangeState(1); nextStepGrid.Cells[x, y].Id = k; } } } } }
public static bool[,] Dilate(this bool[,] input, Neighbourhood neighbourhood, EdgeCondition edgeCondition) { switch (neighbourhood) { case Neighbourhood.Cross: return(input.GenericFilter(3, CrossDilate, edgeCondition, false)); case Neighbourhood.Eight: return(input.GenericFilter(3, EightDilate, edgeCondition, false)); default: throw new NotImplementedException("Neighbourhood " + neighbourhood + " not implemented as dilation"); } }
// GET: Neighbourhoods/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Neighbourhood neighbourhood = db.Neighbourhoods.Find(id); if (neighbourhood == null) { return(HttpNotFound()); } return(View(neighbourhood)); }
public async Task <IHttpActionResult> DeleteNeighbourhood(int id) { Neighbourhood neighbourhood = await db.Neighbourhoods.FindAsync(id); if (neighbourhood == null) { return(NotFound()); } db.Neighbourhoods.Remove(neighbourhood); await db.SaveChangesAsync(); return(Ok(neighbourhood)); }
public void ACellsNeighbourhoodIsEveryLocationAroundACell() { Neighbourhood expected = new Neighbourhood(); expected.AddEmptyCell(0, 1, false); expected.AddEmptyCell(1, 1, false); expected.AddEmptyCell(1, 0, false); expected.AddEmptyCell(1, -1, false); expected.AddEmptyCell(0, -1, false); expected.AddEmptyCell(-1, -1, false); expected.AddEmptyCell(-1, 0, false); expected.AddEmptyCell(-1, 1, false); Cell cell = new Cell(0, 0, true); Assert.AreEqual(expected.ToString(), cell.neighbourhood.ToString()); }
public void FindLargestHouse_WhenComparingALuxuryAndSimpleHouse() { // Arrange House simpleHouse = new TestHouseBuilder().CreateSimpleHouse().Build(); House luxuryHouse = new TestHouseBuilder().CreateComplexHouse(numberOfFloors: 4, roomsPerFloor: 10).Build(); Neighbourhood neighbourhood = TestNeighbourhood.Create().WithHouses(luxuryHouse, simpleHouse); // Act var largestHouse = new HouseFinder(neighbourhood).FindLargestHouse(); // Assert largestHouse.Should().Be(luxuryHouse); }
// GET: Neighbourhoods/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Neighbourhood neighbourhood = db.Neighbourhoods.Find(id); if (neighbourhood == null) { return(HttpNotFound()); } ViewBag.DistrictId = new SelectList(db.Districts, "DistrictId", "DistrictName", neighbourhood.DistrictId); return(View(neighbourhood)); }
public static FormationType GetFormationType( IEnumerable <Unit> units, Vector3 target, CommandType commandType) { if (Neighbourhood.IsNeighbours(units)) { if (units.Any(x => x.Navigation.IsUnitReachedTarget(target))) { return(FormationType.Circle); } else { return(FormationType.Croud); } } return(FormationType.None); }
private static NeigbhourhoodType getNeigbhourhoodType(Neighbourhood neighbourhoodType, BoundaryConditions boundaryConditionsType) { switch (boundaryConditionsType) { case BoundaryConditions.Normal: switch (neighbourhoodType) { case Neighbourhood.Moore: return(NeigbhourhoodType.Moore); case Neighbourhood.VonNoyman: return(NeigbhourhoodType.VonNoyman); case Neighbourhood.RandomPentagonal: return(NeigbhourhoodType.PentagonalRandom); case Neighbourhood.RandomHexagonal: return(NeigbhourhoodType.HexagonalRandom); default: return(NeigbhourhoodType.Moore); } case BoundaryConditions.Periodic: switch (neighbourhoodType) { case Neighbourhood.Moore: return(NeigbhourhoodType.MoorePeriodic); case Neighbourhood.VonNoyman: return(NeigbhourhoodType.VonNoymanPeriodic); case Neighbourhood.RandomPentagonal: return(NeigbhourhoodType.PentagonalRandomPeriodic); case Neighbourhood.RandomHexagonal: return(NeigbhourhoodType.HexagonalRandomPeriodic); default: return(NeigbhourhoodType.MoorePeriodic); } default: return(NeigbhourhoodType.Moore); } }
public Cell(int xcoord, int ycoord, bool extant) { this.xcoord = xcoord; this.ycoord = ycoord; this.extant = extant; if (extant == true) { this.neighbourhood = new Neighbourhood(); this.neighbourhood.AddEmptyCell(this.xcoord + 0, this.ycoord + 1, false); this.neighbourhood.AddEmptyCell(this.xcoord + 1, this.ycoord + 1, false); this.neighbourhood.AddEmptyCell(this.xcoord + 1, this.ycoord + 0, false); this.neighbourhood.AddEmptyCell(this.xcoord + 1, this.ycoord - 1, false); this.neighbourhood.AddEmptyCell(this.xcoord + 0, this.ycoord - 1, false); this.neighbourhood.AddEmptyCell(this.xcoord - 1, this.ycoord - 1, false); this.neighbourhood.AddEmptyCell(this.xcoord - 1, this.ycoord + 0, false); this.neighbourhood.AddEmptyCell(this.xcoord - 1, this.ycoord + 1, false); } }
public void GetNeighbourSolution(int breakout, Neighbourhood neighbourhood) { if (breakout < 1) throw new ArgumentException("Breakout can not be less than 1."); switch (neighbourhood) { case Neighbourhood.SteinerNodeRemoval: GetNeighbourSolutionWithSteinerNodeRemovalNeighbourhood(breakout); break; case Neighbourhood.SteinerNodeInsertion: GetNeighbourSolutionWithSteinerNodeInsertionNeighbourhood(breakout); break; case Neighbourhood.Edge: GetNeighbourSolutionWithEdgeNeighbourhood(breakout); break; } }
public static float GetNeighbourhoodAveragePropertyPrice(Neighbourhood neighbourhood) { int totalPrice = 0; int totalProperties = 0; if (neighbourhood.GetNumInCollection() <= 0) { return(0f); } for (int i = 0; i < neighbourhood.GetNumInCollection(); i++) { totalPrice += neighbourhood.GetProperties()[i].GetPrice(); totalProperties++; } return((float)totalPrice / totalProperties); }
public IEnumerable <Coordinate> GetNeighbours(Neighbourhood neighbourhood) { for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { if (neighbourhood == Neighbourhood.Cross && Mathf.Abs(x) == Mathf.Abs(y)) { continue; } if (x == 0 && y == 0) { continue; } yield return(new Coordinate(this.x + x, this.y + y)); } } }
public void FullHydraulicErosion(int iterations, float rainfall, float evaporation, float solubility, float saturation) { erosionTypeInt = 1; erosionType = ErosionType.Hydraulic; hydraulicTypeInt = 1; hydraulicType = HydraulicType.Full; hydraulicIterations = iterations; hydraulicRainfall = rainfall; hydraulicEvaporation = evaporation; hydraulicSedimentSolubility = solubility; hydraulicSedimentSaturation = saturation; neighbourhood = Neighbourhood.Moore; ErosionProgressDelegate erosionProgressDelegate = new ErosionProgressDelegate(dummyErosionProgress); erodeAllTerrain(erosionProgressDelegate); }
public void FastHydraulicErosion(int iterations, float maxSlope, float blendAmount) { erosionTypeInt = 1; erosionType = ErosionType.Hydraulic; hydraulicTypeInt = 0; hydraulicType = HydraulicType.Fast; hydraulicIterations = iterations; hydraulicMaxSlope = maxSlope; hydraulicFalloff = blendAmount; neighbourhood = Neighbourhood.Moore; ErosionProgressDelegate erosionProgressDelegate = new ErosionProgressDelegate(dummyErosionProgress); erodeAllTerrain(erosionProgressDelegate); }
// -------------------------------------------------------------------------------------------------------- UTILITIES private void convertIntVarsToEnums() { switch (erosionTypeInt) { case 0: erosionType = ErosionType.Thermal; break; case 1: erosionType = ErosionType.Hydraulic; break; case 2: erosionType = ErosionType.Tidal; break; case 3: erosionType = ErosionType.Wind; break; case 4: erosionType = ErosionType.Glacial; break; } switch (hydraulicTypeInt) { case 0: hydraulicType = HydraulicType.Fast; break; case 1: hydraulicType = HydraulicType.Full; break; case 2: hydraulicType = HydraulicType.Velocity; break; } switch (generatorTypeInt) { case 0: generatorType = GeneratorType.Voronoi; break; case 1: generatorType = GeneratorType.DiamondSquare; break; case 2: generatorType = GeneratorType.Perlin; break; case 3: generatorType = GeneratorType.Smooth; break; case 4: generatorType = GeneratorType.Normalise; break; } switch (voronoiTypeInt) { case 0: voronoiType = VoronoiType.Linear; break; case 1: voronoiType = VoronoiType.Sine; break; case 2: voronoiType = VoronoiType.Tangent; break; } switch (neighbourhoodInt) { case 0: neighbourhood = Neighbourhood.Moore; break; case 1: neighbourhood = Neighbourhood.VonNeumann; break; } }
public void WindErosion(int iterations, float direction, float force, float lift, float gravity, float capacity, float entropy, float smoothing) { erosionTypeInt = 3; erosionType = ErosionType.Wind; windIterations = iterations; windDirection = direction; windForce = force; windLift = lift; windGravity = gravity; windCapacity = capacity; windEntropy = entropy; windSmoothing = smoothing; neighbourhood = Neighbourhood.Moore; ErosionProgressDelegate erosionProgressDelegate = new ErosionProgressDelegate(dummyErosionProgress); erodeAllTerrain(erosionProgressDelegate); }
public void VelocityHydraulicErosion(int iterations, float rainfall, float evaporation, float solubility, float saturation, float velocity, float momentum, float entropy, float downcutting) { erosionTypeInt = 1; erosionType = ErosionType.Hydraulic; hydraulicTypeInt = 2; hydraulicType = HydraulicType.Velocity; hydraulicIterations = iterations; hydraulicVelocityRainfall = rainfall; hydraulicVelocityEvaporation = evaporation; hydraulicVelocitySedimentSolubility = solubility; hydraulicVelocitySedimentSaturation = saturation; hydraulicVelocity = velocity; hydraulicMomentum = momentum; hydraulicEntropy = entropy; hydraulicDowncutting = downcutting; neighbourhood = Neighbourhood.Moore; ErosionProgressDelegate erosionProgressDelegate = new ErosionProgressDelegate(dummyErosionProgress); erodeAllTerrain(erosionProgressDelegate); }
public void TidalErosion(int iterations, float seaLevel, float tidalRange, float cliffLimit) { erosionTypeInt = 2; erosionType = ErosionType.Tidal; tidalIterations = iterations; tidalSeaLevel = seaLevel; tidalRangeAmount = tidalRange; tidalCliffLimit = cliffLimit; neighbourhood = Neighbourhood.Moore; ErosionProgressDelegate erosionProgressDelegate = new ErosionProgressDelegate(dummyErosionProgress); erodeAllTerrain(erosionProgressDelegate); }
public Coral(int mapX, int mapY, Neighbourhood neighbourhood) : base(mapX,mapY,neighbourhood) { }
// -------------------------------------------------------------------------------------------------------- API FUNCTIONS public void FastThermalErosion(int iterations, float minSlope, float blendAmount) { erosionTypeInt = 0; erosionType = ErosionType.Thermal; thermalIterations = iterations; thermalMinSlope = minSlope; thermalFalloff = blendAmount; neighbourhood = Neighbourhood.Moore; ErosionProgressDelegate erosionProgressDelegate = new ErosionProgressDelegate(dummyErosionProgress); erodeAllTerrain(erosionProgressDelegate); }
protected ISimulationLogic(int mapX, int mapY, Neighbourhood neighbourhood) { this.mapX = mapX; this.mapY = mapY; this.neighbourhood = neighbourhood; }