Exemplo n.º 1
0
void ARegion::MakeStartingCity()
{
	if(!Globals->TOWNS_EXIST) return;

	if(Globals->GATES_EXIST) gate = -1;
	
	if(town) delete town;
    
    AddTown(TOWN_CITY);

	if(!Globals->START_CITIES_EXIST) return;

	town->hab = 125 * Globals->CITY_POP / 100;
    while (town->pop < town->hab) town->pop += getrandom(200)+200;
    town->dev = TownDevelopment();

	float ratio;
	Market *m;
    markets.DeleteAll();
	if(Globals->START_CITIES_START_UNLIMITED) {
		for (int i=0; i<NITEMS; i++) {
			if( ItemDefs[i].flags & ItemType::DISABLED ) continue;
			if( ItemDefs[ i ].type & IT_NORMAL ) {
				if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN)
					continue;
				m = new Market(M_BUY,i,(ItemDefs[i].baseprice*5/2),-1,
						5000,5000,-1,-1);
				markets.Add(m);
			}
		}
		ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10);
		// hack: include wage factor of 10 in float calculation above
		m=new Market(M_BUY,race,(int)(Wages()*4*ratio),-1, 5000,5000,-1,-1);
		markets.Add(m);
		if(Globals->LEADERS_EXIST) {
			ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10);
			// hack: include wage factor of 10 in float calculation above
			m = new Market(M_BUY,I_LEADERS,(int)(Wages()*4*ratio),
					-1,5000,5000,-1,-1);
			markets.Add(m);
		}
	} else {
		SetupCityMarket();
		ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10);
		// hack: include wage factor of 10 in float calculation above
		/* Setup Recruiting */
		m = new Market( M_BUY, race, (int)(Wages()*4*ratio),
				Population()/5, 0, 10000, 0, 2000 );
		markets.Add(m);
		if( Globals->LEADERS_EXIST ) {
			ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10);
			// hack: include wage factor of 10 in float calculation above
			m = new Market( M_BUY, I_LEADERS, (int)(Wages()*4*ratio),
					Population()/25, 0, 10000, 0, 400 );
			markets.Add(m);
		}
	}
}
Population PopulationGenrator::generatePopulation(int size, int nOfCities) {
	Population population = Population();
	population.paths.reserve(size);

	for(int i = 0; i < size; i++) {
		population.paths.push_back(PathGenerator::generatePath(nOfCities));
	}

	return population;
}
Exemplo n.º 3
0
int Evolution::Init() {
  int n = 10;
  int height_max = 100;

  srand(time(NULL));

  population = Population(n);
  cout << population;

  if(SDL_Init(SDL_INIT_EVERYTHING) < 0) 
    return 0;

  if (!surface.Init()) 
    return 0;

  terrain.Load("heightmap.png");

  return 1;
}
Exemplo n.º 4
0
// Construit une nouvelle simulation à partir de la configuration.
void State::create()
{
    sizeArea = config.sizeArea();

    // Création des obstacles.
    this->addObstacles();

    // Création des pistons.
    for (auto& piston : config.configPistons())
    {
        pistons.push_back(std::make_unique<Piston>(piston, *this));
        pistons.back()->updateCollisions(*this);
    }

    // Création des populations.
    const auto& configPops = config.configPops();
    for (int i = 0 ; i < configPops.size() ; ++i)
    {
        populations.push_back(Population(configPops[i]));
        populations.back().create(i, *this);
    }
}
Exemplo n.º 5
0
int main(int argc, char* argv[])
{
	if (argc < 2)
    {
        printf("The xml definition for the model must be specified.\n");
        printf("  SYNTAX: framework <file.xml>\n\n");
        getc(stdin);
        return 0;
    }
	try
	{
	    char *configFile = argv[1];
		Population p = Population(configFile);
		p.Run();
	}
	catch(char * str )
    {
        printf("\n** Error occured: %s **\n", str);
    }
	//getc(stdin);
	return 0;
}
Exemplo n.º 6
0
/** @brief Split
  *
  * @todo: document this function
  */
void Histogram::Split(std::map<Color, size_t>& otherData, std::vector<Color>& otherColors, ColorCompare& comp)
{
    size_t population = Population();

    std::sort(colors.begin(), colors.end(), comp);

    // Perform Split finding the median color
    size_t median = population / 2;
    size_t fill = 0;
    while (fill < median)
    {
        Color current = colors[0];
        if (fill + data[current] <= median)
        {
            fill += data[current];
            otherColors.push_back(current);
            otherData[current] = data[current];
            data.erase(current);
            colors.erase(colors.begin());
        }
        else
        {
            // If we can get more than half of this color take all of it. But only if it is not the only color remaining.
            if (median - fill > median / 2 && colors.size() > 1)
            {
                fill += data[current];
                otherColors.push_back(current);
                otherData[current] = data[current];
                data.erase(current);
                colors.erase(colors.begin());
            }
            else
            {
                fill = median;
            }
        }
    }
}
Population PopulationGenrator::generatePopulationFrom(Paths paths) {
	return Population();
}
Exemplo n.º 8
0
//--------------------------------------------------------------
void ofApp::setup(){
    population = Population();
}
Exemplo n.º 9
0
/* ---------------------------------------------------------------------- */
const Population  Population::operator +  (const Individual& a) const {
  return Population(*this) += a;
}
Exemplo n.º 10
0
/* ---------------------------------------------------------------------- */
const Population  Population::operator +  (const Population& a) const {
  return Population(*this) += a;
}