void Planet::Tick() { UpdatePopulation(); UpdatePrices(); // Transfer all of the ores from the refinery to out refined stockpile for (uint i = 0; i < m_Refinery.m_RefinedStockpile.GetOreList().size(); ++i) { uint amount = 0; m_Refinery.GiveRefinedOre(m_Refinery.m_RefinedStockpile.GetOreList()[i], &amount); m_RefinedStockpile.AddOreAmount(m_Refinery.m_RefinedStockpile.GetOreList()[i], amount); } //Transfer all the ores from our raw stockpile to the refinery for (uint i = 0; i < m_RawStockpile.GetOreList().size(); ++i) { uint amount = m_RawStockpile.GetOreAmount(m_RawStockpile.GetOreList()[i]); m_Refinery.ReceiveRawOre(m_RawStockpile.GetOreList()[i], amount); m_RawStockpile.SetOreAmount(m_RawStockpile.GetOreList()[i], 0); } // Call Tick() on the refinery m_Refinery.Tick(); // Now we hand all all of the refined ore to m_Factory }
Planet::Planet(uint _id) : m_Factory() { m_id = _id; m_Money = Rand::GetRandomUINT(500, 10000); m_Population = Rand::GetRandomUINT(10, 5000); m_PopulationModifier = Rand::GetRandomFloat(.5, 2); UpdatePrices(); UpdatePopulation(); // Initialize the m_Prices and m_RawStockpile for (Ore i : m_Factory.GetRecipe().GetOreList()) { m_Prices.AddOre(i, 0); m_RawStockpile.AddOre(i, Rand::GetRandomUINT(20, 100)); } }
void GAStep(){ Chromosome *elite = SelectBest(); Chromosome clonA; Chromosome clonB; Chromosome *ap = NULL; // Elitism elite->Clone(&clonA); InsertPobB(&clonA); // harem int fraction = int(HAREM * sizePopulationA); for(int i = 0; i < fraction; i += 2){ elite->Clone(&clonA); SelectTournament()->Clone(&clonB); Crossover(&clonA, &clonB); clonA.Mutate(); clonB.Mutate(); clonA.Fitness() = Distance(&clonA); clonB.Fitness() = Distance(&clonB); InsertPobB(&clonA); InsertPobB(&clonB); } // Fill while((sizePopulationA - sizePopulationB) > 0){ ap = SelectTournament(); ap->Clone(&clonA); ap = SelectTournament(); ap->Clone(&clonB); Crossover(&clonA, &clonB); clonA.Mutate(); clonB.Mutate(); clonA.Fitness() = Distance(&clonA); clonB.Fitness() = Distance(&clonB); if(clonA.Fitness() < clonB.Fitness()) InsertPobB(&clonA); else InsertPobB(&clonB); } UpdatePopulation(); }