public void MakeResidential(CityCell cell) { cell.Type = CellType.Residential; cell.RCapacity = 10; cell.JCapacity = 10; cell.Score = 1; }
public Person(CityCell home) { ID = _stamp; _stamp++; Home = home; Current = home; }
public void Accommodate(int n, CityCell cell) { cell.RCount += n; for (int i = 0; i < n; i++) { Persons.Add(new Person(cell)); } }
public void TearDownOneRCellAndMovePeopleTo(CityCell newCell) { var rCells = Cells.Cast <CityCell>().Where(x => x.Type == CellType.Residential).ToList(); int maxDist = rCells.Max(x => GetDistance(x, newCell)); var cellToTearDown = rCells.First(x => GetDistance(x, newCell) == maxDist); cellToTearDown.Score = 0; cellToTearDown.Type = CellType.Default; foreach (var person in Persons) { if (person.Home == cellToTearDown) { person.Home = newCell; } } }
// A whole day public void Update() { // Go out foreach (var p in Persons) { CityCell destination = ChooseDestination(p); MovePerson(p, destination); } // Go home foreach (var p in Persons) { MovePerson(p, p.Home); } // Update cells foreach (var cell in Cells) { //cell.Type = GetTypeByScore(cell.Score); UpgradeCell(cell); } }
public void InitializeCells() { for (int i = 0; i < ColCount; i++) { for (int j = 0; j < RowCount; j++) { Cells[i, j] = new CityCell(i, j); } } Random rand = new Random(); for (int i = 0; i < InitialRCellCount; i++) { int x = rand.Next(0, ColCount); int y = rand.Next(0, RowCount); CityCell cell = Cells[x, y]; this.MakeResidential(cell); this.Accommodate(10, cell); } }
public void MovePerson(Person p, CityCell to) { CityCell from = p.Current; from.RCount--; to.RCount++; p.Current = to; AStar astar = new AStar(_AStarGrid, from.Col, from.Row, to.Col, to.Row); astar.search(); foreach (var step in astar.path) { Cells[step.x, step.y].Score++; } //var pathSides = astar.getPathSides(); //foreach (var node in pathSides) //{ // Cells[node.x, node.y].Score++; //} }
public void UpgradeCell(CityCell cell) { CellType realType = cell.Type; CellType qualifiedType = GetTypeByScore(cell.Score); if (qualifiedType != realType) { if (_rand.NextDouble() < UpgradeProbability) { cell.Type = qualifiedType; cell.JCapacity = qualifiedType == CellType.Hotel ? 20 : qualifiedType == CellType.Commercial ? 30 : qualifiedType == CellType.Industrial ? 40 : 10; if (qualifiedType == CellType.Residential) { if (_rand.NextDouble() < MigrationProbability) { TearDownOneRCellAndMovePeopleTo(cell); } } } } }
public int GetDistance(CityCell a, CityCell b) { return(Math.Abs(a.Col - b.Col) + Math.Abs(a.Row - b.Row)); }