Example #1
0
//----------------------------------------------------------------------------------------------------------------------
void Tornado::createParticleSystem()
{
  //creates new particle systems if the particle systems count hasn't reached the treshold
    if (m_particleSystemCount < m_particleSystemTreshold)
    {

      //changing the every 50 frames how often the radius should change
        if(m_frame%50==0)
        {
          //gets a random change value from 10 to 100 frames
        std::random_device rd2;
        std::mt19937_64 gen(rd2());

        std::uniform_int_distribution<int> distribution2(10,100);
        m_radiusChange = (float)distribution2(gen);

        //gets a random value from the range of 2-4 that controlls how much the diffrent of the radius should be
        std::uniform_int_distribution<int> distribution3(2,4);
        m_radiusDiffrence=distribution3(gen);
        }
        //creating particle systems
        int diffrence=m_particleSystemTreshold - m_particleSystemCount;
        for (int i=0; i<diffrence;i++)
        {
          //gets a random radius from the radius range
            std::random_device rd;
            std::mt19937_64 gen(rd());

            std::uniform_real_distribution<float> distribution(m_radiusRange[0],m_radiusRange[1]);
            float radius = distribution(gen);
            // caclucaltes the radius the is added on top of the original radius to create a ring type shape
            radius+= sqrt(pow((m_radiusDiffrence*sin((1.0/m_radiusChange)*(float)m_frame)),2));

            // gets a random offset value
            std::uniform_real_distribution<float> distribution1(0.0,20.0);
            float offset = distribution1(gen);

            m_particleSystemList.push_back(std::unique_ptr<ParticleSystem>(new ParticleSystem(radius,offset,m_particleState,m_cloudHeight,m_particleProdutionRate,m_particleLifeRange)));

            m_particleSystemCount++;

            if (m_particleSystemCount >= m_particleSystemTreshold){ return;}
            if (i >= m_maxProductionRate){return;}

        }
    }


}
void ZombieGenetics::Crossover(std::mt19937& a_random)
{
	unsigned int childCount = ChildCount();

	const float crossoverChance = 70.0f;

	for (int i = 0; i < childCount; i++)
	{
		Zombie	*childGenes = children[i].genes[0],
				*parent1Genes = parents[i * 2]->genes[0],
				*parent2Genes = parents[i * 2 + 1]->genes[0];

		childGenes->parentTraits.clear();
		childGenes->parentTraits.push_back(ParentTraits(parents[i * 2]->fitness, parent1Genes->speed, parent1Genes->strength, parent1Genes->maxHealth, parent1Genes->scale, parent1Genes->specialTraits));
		childGenes->parentTraits.push_back(ParentTraits(parents[i * 2 + 1]->fitness, parent2Genes->speed, parent2Genes->strength, parent2Genes->maxHealth, parent2Genes->scale, parent2Genes->specialTraits));

		std::uniform_real_distribution<float> distribution(0.0f, 99.0f);

#pragma region MAX_HEALTH
		if (distribution(a_random) - crossoverChance < 0.0f)
			childGenes->maxHealthRange.x = parent1Genes->maxHealthRange.x + parent2Genes->maxHealthRange.x / 2.0f;
		else
			childGenes->maxHealthRange.x = parent1Genes->maxHealthRange.x;

		if (distribution(a_random) - crossoverChance < 0.0f)
			childGenes->maxHealthRange.y = parent1Genes->maxHealthRange.y + parent2Genes->maxHealthRange.y / 2.0f;
		else
			childGenes->maxHealthRange.y = parent1Genes->maxHealthRange.y;
#pragma endregion MAX_HEALTH

#pragma region SIZE
		if (distribution(a_random) - crossoverChance < 0.0f)
			childGenes->scaleRange.x = parent1Genes->scaleRange.x + parent2Genes->scaleRange.x / 2.0f;
		else
			childGenes->scaleRange.x = parent1Genes->scaleRange.x;

		if (distribution(a_random) - crossoverChance < 0.0f)
			childGenes->scaleRange.y = parent1Genes->scaleRange.y + parent2Genes->scaleRange.y / 2.0f;
		else
			childGenes->scaleRange.y = parent1Genes->scaleRange.y;
#pragma endregion SIZE

#pragma region SPEED
		if (distribution(a_random) - crossoverChance < 0.0f)
			childGenes->speedRange.x = parent1Genes->speedRange.x + parent2Genes->speedRange.x / 2.0f;
		else
			childGenes->speedRange.x = parent1Genes->speedRange.x;

		if (distribution(a_random) - crossoverChance < 0.0f)
			childGenes->speedRange.y = parent1Genes->speedRange.y + parent2Genes->speedRange.y / 2.0f;
		else
			childGenes->speedRange.y = parent1Genes->speedRange.y;
#pragma endregion SPEED

#pragma region STRENGTH
		if (distribution(a_random) - crossoverChance < 0.0f)
			childGenes->strengthRange.x = parent1Genes->strengthRange.x + parent2Genes->strengthRange.x / 2.0f;
		else
			childGenes->strengthRange.x = parent1Genes->strengthRange.x;

		if (distribution(a_random) - crossoverChance < 0.0f)
			childGenes->strengthRange.y = parent1Genes->strengthRange.y + parent2Genes->strengthRange.y / 2.0f;
		else
			childGenes->strengthRange.y = parent1Genes->strengthRange.y;
#pragma endregion STRENGTH

#pragma region SPECIAL_TRAITS
		std::uniform_int_distribution<int> distribution2(0, 1);

		for (int j = 1; j != 256; j *= 2)
		{
			if (distribution2(a_random))
				childGenes->specialTraits |= parent1Genes->specialTraits & j;
			else
				childGenes->specialTraits |= parent2Genes->specialTraits & j;
		}
#pragma endregion SPECIAL_TRAITS
	}
}