public string GetNumberOfStages(List <int> numStages) { string stages = ""; if (numStages.Count == 12) { stages = "All stages "; } else { for (int i = 0; i < numStages.Count; i++) { stages += numStages[i].ToString() + " "; } } return(stages); }
public List <Stages> BuildStages(int population) { int farFromStages = Convert.ToInt32(population * 0.1); int mainPart = Convert.ToInt32(population * 0.2355) + 1; //Stages number 4 7 10 11 int otherPeople = population - (mainPart + farFromStages); int mainPartTemp = mainPart; int mainPartIncludeAll = 0, otherPeopleIncludeAll = 0; int otherPeopleTemp = otherPeople; double ratio; Random rnd = new Random(); List <Stages> listStages = new List <Stages>(); //Far away people Stages far = new Stages(); far.numStage = 0; far.numPeople = farFromStages; listStages.Add(far); //Insert random people to all stages. for (int i = 1; i <= 11; i++) { Stages stage = new Stages(); stage.numStage = i; if (i == 4 || i == 7 || i == 10 || i == 11) //main part people { if (i == 11) //last stage { stage.numPeople = mainPart - mainPartIncludeAll; } else { ratio = ((double)mainPart / 4) / ((double)mainPartTemp / 2); if (ratio > 1) { ratio = 1; } stage.numPeople = Convert.ToInt32((rnd.Next(1, mainPartTemp)) * ratio); } mainPartTemp -= stage.numPeople; mainPartIncludeAll += stage.numPeople; } else { if (i == 9) // last stage { stage.numPeople = otherPeople - otherPeopleIncludeAll; } else //other stages { ratio = ((double)otherPeople / 7) / ((double)otherPeopleTemp / 2); if (ratio > 1) { ratio = 1; } stage.numPeople = Convert.ToInt32((rnd.Next(1, otherPeopleTemp)) * ratio); } otherPeopleTemp -= stage.numPeople; otherPeopleIncludeAll += stage.numPeople; } listStages.Add(stage); } //--print to console --- Console.WriteLine("Main part: " + mainPartIncludeAll + " Other: " + otherPeopleIncludeAll); foreach (Stages s in listStages) { Console.WriteLine("Stage: " + s.numStage + " Number people: " + s.numPeople); } return(listStages); }