Ejemplo n.º 1
0
        private ZoneMap GenerateZones(ZoneMap zones)
        {
            for (int x = 0; x < _cityWidth; x++)
            {
                for (int y = 0; y < _cityHeight; y++)
                {
                    int shiftedX = x + 2;
                    int shiftedY = y + 2;
                    if (x % 4 == 0 || y % 4 == 0)
                    {
                        if (x % 4 == 0 && y % 4 == 0)
                        {
                            zones.Map[x, y] = Zone.Intersection;
                        }
                        else
                        {
                            zones.Map[x, y] = Zone.Road;
                        }
                    }
                    //Leave center of blocks Vacant
                    else if (shiftedX % 4 == 0 && shiftedY % 4 == 0)
                    {
                        zones.Map[x, y] = Zone.Vacant;
                    }
                    else
                    {
                        //If the percent from center is greater than 75% it will always be a house
                        double rng = _rand.Next(75);
                        rng = rng / 100;
                        //Calculate maximum distance from center of map
                        var maxXSquared = _cityWidth / 2;
                        var maxYSquared = _cityHeight / 2;
                        //Calculated current position relative to center of map
                        var xSquared = x - maxXSquared;
                        var ySquared = y - maxYSquared;
                        //Square max value
                        maxXSquared = maxXSquared * maxXSquared;
                        maxYSquared = maxYSquared * maxYSquared;
                        //Square current positon
                        xSquared = xSquared * xSquared;
                        ySquared = ySquared * ySquared;
                        //Calculate percent from center of the map
                        var distanceFromCenter = Math.Sqrt(xSquared + ySquared);
                        var percentFromCenter  = distanceFromCenter / Math.Sqrt(maxXSquared + maxYSquared);

                        if (rng < percentFromCenter)
                        {
                            zones.Map[x, y] = Zone.Residential;
                        }
                        else
                        {
                            zones.Map[x, y] = Zone.Work;
                        }
                    }
                }
            }
            return(zones);
        }
Ejemplo n.º 2
0
        public City(StartingValues startValues)
        {
            storagePathPeople = startValues.StoragePath;
            storagePathMap = startValues.StoragePathMap;

            mManager = new TrafficMutator();
            _budget = startValues.Budget;
             _traffictCycleTime = startValues.TrafficLightCycleTimeDefault;
            _cityHeight = startValues.MapHeight;
            _cityWidth = startValues.MapWidth;
            _population = startValues.Population;
            _zoning = new ZoneMap(_cityWidth,_cityHeight);

            LiveMap = new ITile[_cityWidth, _cityHeight];

            TravelTimes = new int[_cityWidth, _cityHeight];

            if (File.Exists(storagePathPeople))
            {
                //GeneratePeople();
                LoadPeopleFromFile();

            }
            else
            {
                _zoning = GenerateZones(_zoning);
                LiveMap = GenerateLiveMap(LiveMap);
                GenerateTravelTimeHelper();
                GeneratePeople();
            }

            PrintCity();
            //The larger the number the more accurate the final prediction
            while (mManager.GetNumberOfCyclesSinceLastKeptChange() < 200000)
             {
                 Tick();
             }

             Console.Out.WriteLine("The ideal intersection timing for this city is... [Measured in ticks]");
            PrintFinalOutput();
        }
Ejemplo n.º 3
0
        public City(StartingValues startValues)
        {
            storagePathPeople = startValues.StoragePath;
            storagePathMap    = startValues.StoragePathMap;

            mManager           = new TrafficMutator();
            _budget            = startValues.Budget;
            _traffictCycleTime = startValues.TrafficLightCycleTimeDefault;
            _cityHeight        = startValues.MapHeight;
            _cityWidth         = startValues.MapWidth;
            _population        = startValues.Population;
            _zoning            = new ZoneMap(_cityWidth, _cityHeight);

            LiveMap = new ITile[_cityWidth, _cityHeight];

            TravelTimes = new int[_cityWidth, _cityHeight];


            if (File.Exists(storagePathPeople))
            {
                //GeneratePeople();
                LoadPeopleFromFile();
            }
            else
            {
                _zoning = GenerateZones(_zoning);
                LiveMap = GenerateLiveMap(LiveMap);
                GenerateTravelTimeHelper();
                GeneratePeople();
            }

            PrintCity();
            //The larger the number the more accurate the final prediction
            while (mManager.GetNumberOfCyclesSinceLastKeptChange() < 200000)
            {
                Tick();
            }

            Console.Out.WriteLine("The ideal intersection timing for this city is... [Measured in ticks]");
            PrintFinalOutput();
        }
Ejemplo n.º 4
0
        private ZoneMap GenerateZones(ZoneMap zones)
        {
            for (int x = 0; x < _cityWidth; x++)
            {
                for (int y = 0; y < _cityHeight; y++)
                {
                    int shiftedX = x + 2;
                    int shiftedY = y + 2;
                    if (x%4 == 0|| y%4 == 0)
                    {

                        if (x%4 == 0 && y%4 == 0)
                        {
                            zones.Map[x, y] = Zone.Intersection;
                        }
                        else
                        {
                            zones.Map[x, y] = Zone.Road;
                        }

                    }
                    //Leave center of blocks Vacant
                    else if (shiftedX%4 == 0 && shiftedY%4 == 0)
                    {
                        zones.Map[x, y] = Zone.Vacant;
                    }
                        else
                    {

                        //If the percent from center is greater than 75% it will always be a house
                        double rng = _rand.Next(75);
                        rng = rng/100;
                        //Calculate maximum distance from center of map
                        var maxXSquared = _cityWidth/2;
                        var maxYSquared = _cityHeight/2;
                        //Calculated current position relative to center of map
                        var xSquared = x - maxXSquared;
                        var ySquared = y - maxYSquared;
                        //Square max value
                        maxXSquared = maxXSquared * maxXSquared;
                        maxYSquared = maxYSquared * maxYSquared;
                        //Square current positon
                        xSquared = xSquared * xSquared;
                        ySquared = ySquared * ySquared;
                        //Calculate percent from center of the map
                        var distanceFromCenter = Math.Sqrt(xSquared + ySquared);
                        var percentFromCenter = distanceFromCenter/Math.Sqrt(maxXSquared + maxYSquared);

                        if (rng < percentFromCenter)
                        {
                            zones.Map[x, y] = Zone.Residential;
                        }
                        else
                        {
                            zones.Map[x, y] = Zone.Work;
                        }
                    }

                }

            }
            return zones;
        }