Beispiel #1
0
 public void MakeResidential(CityCell cell)
 {
     cell.Type      = CellType.Residential;
     cell.RCapacity = 10;
     cell.JCapacity = 10;
     cell.Score     = 1;
 }
Beispiel #2
0
 public Person(CityCell home)
 {
     ID = _stamp;
     _stamp++;
     Home    = home;
     Current = home;
 }
Beispiel #3
0
 public void Accommodate(int n, CityCell cell)
 {
     cell.RCount += n;
     for (int i = 0; i < n; i++)
     {
         Persons.Add(new Person(cell));
     }
 }
Beispiel #4
0
        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;
                }
            }
        }
Beispiel #5
0
 // 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);
     }
 }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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++;
            //}
        }
Beispiel #8
0
        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);
                        }
                    }
                }
            }
        }
Beispiel #9
0
 public int GetDistance(CityCell a, CityCell b)
 {
     return(Math.Abs(a.Col - b.Col) + Math.Abs(a.Row - b.Row));
 }