public Map(PopulationSegment[,] mapSegments, long populationSize) { _size = new Size(((Array)mapSegments).GetLength(0),((Array)mapSegments).GetLength(1)); Regions = new Region[(int)_size.Width, (int)_size.Height]; long lostPop = populationSize; for (int w = 0; w < _size.Width; w++) for (int h = 0; h < _size.Height; h++) { var r = new Region(new Location(w, h), Initializer.GetImplementation<IHistoryManager<Region>>()); Regions[w, h] = r; r.Settle(new Population(populationSize,mapSegments[w,h])); lostPop -= r.PopulationSize; if ((w + 1) * (h + 1) == _size.Square) if (lostPop != 0) r.Settle(lostPop); r.SetBizSquare(); } }
public static PopulationSegment[,] GenerateSegments(int w, int h) { var maxLvl = 5; var perc = 100.0d; double sumPerc = 0d; var popSegm = new PopulationSegment[w, h]; var rndL = new Random(); var rndD = new Random(); var precis = 1000000.0f; for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) { int lvl = rndL.Next(maxLvl) + 1; var maxD = ((2.7d*100 * precis)/(w*h*lvl)) + 1; double density = 0; if ((i + 1) * (j + 1) == w * h) density = perc; else { density = rndD.Next((int)maxD) / precis; density = density > ((2.7f * 100) / (w * h * lvl)) ? (2.7f * 100) / (w * h * lvl) : density; perc = perc - density; } sumPerc += density; density = sumPerc > 100f ? (density - (sumPerc - 100f)) : density; popSegm[i, j] = new PopulationSegment( density, lvl ); } return popSegm; }
public Population(long populationSize, PopulationSegment populationSegment) { this.PopulationSize = (long)(populationSize * populationSegment.Density/100); this._populationSegment = populationSegment; }