Exemplo n.º 1
0
void movimentaInimigos(){
    for (int i = 0; i < inimigos.size(); i++) {
        inimigo a = inimigos[i];
        
        (rand()%10)/2 == 0 ? a.posX += randfrom(0, 10) : a.posX -= randfrom(0, 10);
        (rand()%10)/2 == 0 ? a.posZ += randfrom(0, 10) : a.posZ -= randfrom(0, 10);
        if(i == 0){
            //printf("X: %f - Z: %f\n",a.posX,a.posZ);
        }
    }
}
Exemplo n.º 2
0
void criaInimigos(int qtd){
    if (inimigos.size() > 0) {
        movimentaInimigos();
    }else{
        for (int i = 0; i < qtd; i++) {
            inimigo aux;
            aux.posX = (rand()%10)/2 == 0 ? randfrom(0, 300) : -randfrom(0, 300);
            aux.posY = 400;
            aux.posZ = (rand()%10)/2 == 0 ? randfrom(0, 300) : -randfrom(0, 300);
            
            inimigos.push_back(aux);
        }
        criaInimigos(qtd);
    }
}
int CreateDenseMatrixGeneral(char *fileName, unsigned long int numRows, unsigned long int numCols, unsigned int seed, double min, double max) {
//Options: numRows numCols fileName seed

	FILE *output;
	//long nz;   
	unsigned long int i, j;
	MM_typecode outputmatcode;
	
	mm_initialize_typecode(&outputmatcode);
	mm_set_matrix(&outputmatcode);
	mm_set_coordinate(&outputmatcode);
	//mm_set_dense(&outputmatcode);
	mm_set_real(&outputmatcode);
	mm_set_general(&outputmatcode);
	
	if(strcmp(fileName,"stdout")==0){
		output = stdout;
	}
	else{
		if ((output = fopen(fileName, "w")) == NULL){
			fprintf(stderr,"[%s] Unable to open file for writing\n",__func__);
			return 0;
		}
	}
			
	
	double value = 0.0;
	
	srand (seed);

	mm_write_banner(output, outputmatcode);
	mm_write_mtx_crd_size(output, numRows, numCols, numRows*numCols);
	//ret_code = fprintf(output,"\%\%MatrixMarket matrix coordinate real symmetric\n");
	
	//unsigned long long int val1 = 0;
	//unsigned long long int val2 = 0;
	

	
	for(i = 0;i < numRows; i++){
	
		for(j = 0; j< numCols; j++){

            value = randfrom(min, max);
			fprintf(output, "%lu %lu %lg\n",i+1,j+1,value);

		}

	}
	

	fclose(output);

	return 1;
}
Exemplo n.º 4
0
/**
 *	Initialize a neuron with random weights and tanh as transfer function.
 *	Has to be given the number of inputs.
 */
pNeuron create_random_neuron (neuron_head input_neuron_head) {
	if (NULL == input_neuron_head) {
		perror ("Empty list of input neurons. Can't create new neuron.");
		exit (EXIT_FAILURE);
	}

    pNeuron cur_neuron = (pNeuron) malloc (sizeof(struct neuron));
    if (NULL == cur_neuron) {
        perror ("Not enough memory to create neuron.");
        exit (EXIT_FAILURE);
    }

	// Init standard values.
    cur_neuron->output = 0;
    cur_neuron->net_sum = 0;
    cur_neuron->transfer = &tanh;

    // Init first weight. It's for the bias and therefore has no belonging neuron.
    weight_head cur_weight_head = create_weight_node (randfrom(-0.5, 0.5), NULL);
    weight_head weights = cur_weight_head, prev_weight_head = NULL;

    unsigned int first_index = input_neuron_head->index;

	// Loop through input neurons and create weights for every neuron.
	do {
		// Initialize the new current weight randomly, point it to the current neuron.
		cur_weight_head = create_weight_node (randfrom(-0.5, 0.5), input_neuron_head->current_neuron);

		// If we have a previous weight node, point it to the current weight node
		if (NULL != prev_weight_head) {
			prev_weight_head->next = cur_weight_head;
		}

		// Move to next element in input list.
		prev_weight_head = cur_weight_head;
		if (NULL != input_neuron_head->next) input_neuron_head = input_neuron_head->next;
	} while (input_neuron_head->index != first_index);

    cur_neuron->weights		  = weights;

    return cur_neuron;
}