Exemple #1
0
	void BRAIN::build(int nb_in,int nb_out,int rg)				// Create the neural network
	{
		destroy();
		q = rg;
		nb_neuron = q + nb_in + nb_out;		// Number of layers * number of input NEURONs + number of output NEURONs
		n = nb_in;
		p = nb_out;
		neuron = new NEURON[nb_neuron];
		n_out = new float[nb_out];
		for(int i = 0; i < nb_neuron; ++i)
		{
			neuron[i].var = 0.0f;
			neuron[i].weight = NULL;
			if (i < nb_out)
				n_out[i] = 0.0f;
			if (i >= n && i < nb_neuron - p)
			{
				neuron[i].weight = new float[n];
				for(int e = 0 ; e < n ; ++e)
					neuron[i].weight[e] = float(TA3D_RAND() % 2001) * 0.001f - 1.0f;
			}
			else
			{
				if (i >= n)
				{
					neuron[i].weight = new float[q];
					for(int e = 0 ; e < q ; ++e)
						neuron[i].weight[e] = float(TA3D_RAND() % 2001) * 0.001f - 1.0f;
				}
			}
		}
	}
Exemple #2
0
	void BRAIN::mutation()			// Make some changes to the neural network
	{
		int index = (TA3D_RAND() % (nb_neuron-n)) + n;
		int mod_w = 0;
		if (index < nb_neuron - p)
			mod_w=TA3D_RAND() % n;
		else
			mod_w = TA3D_RAND() % q;
		neuron[index].weight[mod_w] += float((TA3D_RAND() % 200001) - 100000) * 0.00001f;
	}
Exemple #3
0
	void Camera::updateShake(const float dt)
	{
		if (shakeDuration > 0.0f)
		{
			shakeDuration -= dt;
			float dt_step = 0.03f;
			for (float c_dt = 0.0f ; c_dt < dt ; c_dt += dt_step)
			{
				float rdt = Math::Min(dt_step, dt - c_dt);
				Vector3D rand_vec( float((TA3D_RAND() % 2001) - 1000) * 0.001f * shakeMagnitude,
								   float((TA3D_RAND() % 2001) - 1000) * 0.001f * shakeMagnitude,
								   float((TA3D_RAND() % 2001) - 1000) * 0.001f * shakeMagnitude );
				shakeVector += -rdt * 10.0f * shakeVector;
				shakeVector += rand_vec;
				if (shakeVector.x < -20.0f)		shakeVector.x = -20.0f;
				else if(shakeVector.x > 20.0f)	shakeVector.x = 20.0f;
				if (shakeVector.y < -20.0f )	shakeVector.y = -20.0f;
				else if(shakeVector.y > 20.0f)	shakeVector.y = 20.0f;
				if (shakeVector.z < -20.0f)		shakeVector.z = -20.0f;
				else if(shakeVector.z > 20.0f)	shakeVector.z = 20.0f;
			}
		}
		else
		{
			float dt_step = 0.03f;
			for (float c_dt = 0.0f; c_dt < dt; c_dt += dt_step)
			{
				float rdt = Math::Min(dt_step, dt - c_dt);
				shakeVector += -rdt * 10.0f * shakeVector;

				if( shakeVector.x < -20.0f )    shakeVector.x = -20.0f;
				else
					if( shakeVector.x > 20.0f)	shakeVector.x = 20.0f;
				if (shakeVector.y < -20.0f)     shakeVector.y = -20.0f;
				else
					if( shakeVector.y > 20.0f)	shakeVector.y = 20.0f;
				if (shakeVector.z < -20.0f)     shakeVector.z = -20.0f;
				else
					if( shakeVector.z > 20.0f)	shakeVector.z = 20.0f;
			}
		}
	}