예제 #1
0
파일: qs.c 프로젝트: zz-mars/zz-repo
int main(int argc, char * argv[]) {
	int a[ARRAY_LEN];
	randGenerator(a, ARRAY_LEN, 500);
	printIntarray(a, ARRAY_LEN);
	int x = find_kth_largest(a, ARRAY_LEN, 3);
	printf("third -> %d\n", x);
	quick_sort(a, 0, ARRAY_LEN);
//	quick_partition(a, 0, ARRAY_LEN);
	printIntarray(a, ARRAY_LEN);
	return 0;
}
예제 #2
0
int main()
{
	/* Keep this line here */
	srand(time(NULL));

	int *arr = malloc(ARRLEN*sizeof(int));
	int num;

	if (!arr) {
		return -1;
	}

	randGenerator(arr, ARRLEN);
	num = oddball(arr, ARRLEN);

	printf("Oddball is %d\n", num);

	return 0;
}
예제 #3
0
파일: sort_test.c 프로젝트: zz-mars/zz-repo
int main()
{
	int a[ELEM_N];
	randGenerator(a,ELEM_N,1000);

	printIntarray(a,ELEM_N);
//	insertionSort(a,ELEM_N);
//	selectSort(a,ELEM_N);
//	shellSort(a,ELEM_N);
//	bubbleSort(a,ELEM_N);
	quickSort(a,ELEM_N);
//	heapSort(a,ELEM_N);
//	radixSort(a,ELEM_N);
//	countingSort(a,ELEM_N);
//	mergeSort(a,ELEM_N);
	printIntarray(a,ELEM_N);

	return 0;
}
예제 #4
0
int main(){
  
  int numeros;
  int* randnum;
  listas* lista==NULL;
  colas* cola==NULL;
  pilas* pila==NULL;
  printf("Cuantos numeros quiere generar?:");
  scanf("%d",&numeros);
  randGenerator(numeros,randnum);
  
  
  
  
  
  
  
  
  
}
예제 #5
0
int main(int argc, char* argv[]) {
  clock_t start, stop;
	start = clock();
	int v = atoi(argv[1]);
	printf("The random seed is: %d \n", v);
	srand(v);

    GenRandGenerator randGenerator( v );

    LevelGenerator<GenRandGenerator> levelGenerator( randGenerator );
    levelGenerator.generateLevels();

    NumRoomsMetric numRoomsMetric;
    Level & l( levelGenerator.pickLevelByCriteria( numRoomsMetric ) );
    printLevel( l );

    stop = clock();
    long clocks_per_ms = CLOCKS_PER_SEC/1000;
    printf("%ld\n", (stop - start)/clocks_per_ms);

    return 0;
}
예제 #6
0
파일: cNN.c 프로젝트: arturo393/IRMA
/**
 * Crea una capa de \a neuronNum neuronas. Cada neurona de la capa tendrá
 * \a wgtNum pesos. El identificador de la capa deberá también indicarse.
 * \param neuronNum Número entero de neuronas que contiene la capa.
 * \param wgtNum Número entero de pesos que posee cada neurona.
 * \param layer Número entero para indicar el identificador de la capa de neuronas.
 * \return la capa de neuronas creada (puntero a pnnLayer).
 */
pnnLayer cConceptualNN::createLayerOfNeurons( int neuronNum, int wgtNum, int layer )
{
    pnnLayer  tempLayer = NULL;

    pnnStruct tempNeuron = NULL;  //puntero a la lista de nodos neuronales
    pnnStruct tempNeuron2 = NULL; //puntero al nodo neuronal creado

    pnnWeight tempWgth = NULL;    //puntero a la lista de nodos pesos
    pnnWeight tempWgth2 = NULL;   //puntero al nodo peso creado

    if ( neuronNum <= 0 || wgtNum < 0 )
    {
        printf( "Error: El número de neuronas indicados o el número de" );
        printf( " pesos indicados es menor o igual a cero.\nSe sale "   );
        exit(1);
    }

    tempLayer = this->createLayer();                          //se crea capa de neuranas vacía
    this->setLayerNode(tempLayer, layer, neuronNum);          //se inicializa capa de neuronas

    // procedimiento para crear las neuronas de la capa
    for( int i = neuronNum -1; i >= 0 ; i-- )
    {
        tempNeuron2 = this->createNeuralNode();               //se crea nodo vacío

        //NOTA, MEJOR SERÍA HACER UNA SIGMOIDE...
        this->setNeuralNode( tempNeuron2, i, layer, UMBRAL);  //se inicializa el nodo

        //procedimiento para crear los pesos de cada neurona dependiendo del wgtNum
        //para red marbot wgtNum es equivalente al número de neuronas de la capa previa
        //para red som wgtNum es equivalente al número de neuronas con vecindad radio 1
        if(wgtNum > 0)
        {
            for( int j = wgtNum-1; j >= 0 ; j-- )
            {
                tempWgth2 = this->createWeightNode();         //se crea nodo peso vacío
                this->setWeight( tempWgth2, randGenerator(), i, j );  //se inicializa nodo peso
         //       printf("peso %f ",tempWgth2->wgth);

                //procedimiento para primer nodo peso creado
//                if(j <= wgtNum -1) tempWgth = tempWgth2;
//
//                else
                     this->addWeightNode2WeightNode(&tempWgth,  //se agrega a la lista de
                                                    &tempWgth2);//nodos pesos el nuevo nodo
                                                               //creado
                // printf("peso %f\n",tempWgth->wgth);
            }
            this->addWeight2NeuralNode(tempWgth,               //se agrega la lista de nodos
                                       &tempNeuron2);           //pesos a la neurona creada.
        }

        //procedimiento para el primer nodo neuronal creado
//        if (i <= neuronNum -1) tempNeuron = tempNeuron2;
//
//        else
             this->addNeuralNode2NeuralNode(&tempNeuron,        //se agrega a la lista de nodos
                                            &tempNeuron2);      //neuronales el nuevo nodo neuronal
                                                               //creado.
    }
    this->addNeuralNode2Layer( &tempLayer, tempNeuron ); //se agrega neuronas a la capa
    return (tempLayer);
}
예제 #7
0
void GameplayScreen::init()
{
	b2Vec2 gravity(0.0f, -50.0f);
	//create up world
	mWorld = std::make_unique<b2World>(gravity);

	//Add Ground body
	b2BodyDef groundBodyDef;
	groundBodyDef.position.Set(0.0f, -20.0f); // units of meters
	b2Body* groundBody = mWorld->CreateBody(&groundBodyDef);
	//Shape is a polygon, fixture keeps them together
	b2PolygonShape groundBox;
	groundBox.SetAsBox(50.0f, 10.0f);
	groundBody->CreateFixture(&groundBox, 0.0f);

	//Load texture
	mTexture = WebEngine::ResourceManager::getTexture("Assets/bricks_top.png");

	WebEngine::ColorRGBA8 color(255, 0, 0, 255);

	//Add a bunch of boxes
	std::mt19937 randGenerator(time(nullptr));
	std::uniform_real_distribution<float> xPos(-10.0f, 10.0f);
	std::uniform_real_distribution<float> yPos(-15.0f, 15.0f);
	std::uniform_real_distribution<float> size(0.5f, 2.5f);
	std::uniform_int_distribution<unsigned int> randColor(0, 255);
	const int numBoxes = 20;

	for (int i = 0; i < numBoxes; i++)
	{
		WebEngine::ColorRGBA8 color(randColor(randGenerator), randColor(randGenerator), randColor(randGenerator), 255);
		Box newBox;
		newBox.init(mWorld.get(), glm::vec2(xPos(randGenerator), yPos(randGenerator)), glm::vec2(size(randGenerator), size(randGenerator)), mTexture, color);
		//Box memory can be discraded because the important bits are stored in the world
		mBoxes.push_back(newBox);
	}

	//Initialize shaders
	//Compile texture shader
	mTextureProgram.compileShaders("Shaders/textureShading.vert", "Shaders/textureShading.frag");
	mTextureProgram.addAttribute("vertexPosition");
	mTextureProgram.addAttribute("vertexColor");
	mTextureProgram.addAttribute("vertexUV");
	mTextureProgram.linkShaders();
	//Compile light shader
	mLightProgram.compileShaders("Shaders/lightShading.vert", "Shaders/lightShading.frag");
	mLightProgram.addAttribute("vertexPosition");
	mLightProgram.addAttribute("vertexColor");
	mLightProgram.addAttribute("vertexUV");
	mLightProgram.linkShaders();

	mDebugRenderer.init();
	m_CameraController.init(&mCamera, mTime);
	//Initialize spritebatch
	mSpriteBatch.init();

	//Init camera
	mCamera.init(mWindow->getScreenWidth(), mWindow->getScreenHeight());
	mCamera.setScale(32.0f); //32 pixels per meter, good scale

	mPlayer.init(mWorld.get(), glm::vec2(0.0f, 30.0f), glm::vec2(1.0f), glm::vec2(0.5f, 1.0f), WebEngine::ColorRGBA8(255, 255, 255, 255));
}
예제 #8
0
파일: a3.c 프로젝트: homaseif/a3
int main(int argc, char *argv[]){
	int flag = 0;
	int streetsNumb = 10;
	int lineSegmentsNumb = 5;
	int waitingTime = 5;
	int coordinatesRange = 20;

	int i;
	int j;
	int k;
	for(i = 1; i < argc; i += 2){
		if(strcmp(argv[i], "-s") == 0){
			streetsNumb = atoi(argv[i+1]);//lower bound: 2
		}
		else if(strcmp(argv[i], "-n") == 0) {
			lineSegmentsNumb = atoi(argv[i+1]);//lower bound: 1
		}
		else if(strcmp(argv[i], "-l") == 0){
			waitingTime = atoi(argv[i+1]);//lower bound: 5
		}
		else if(strcmp(argv[i], "-c") == 0){
			coordinatesRange = atoi(argv[i+1]);//lower bound: 1
		}
	}
	int attempts = 0;//for unseccssful tries
	int attemptsBound = 25;
	int xtmp;
	int ytmp;
	char c;
	while(1){
		if(flag == 1){
			for(i = 0; i < streetsNumb; i++)
                        	printf("r \"%d\"\n", i);
		}
		flag = 1;
		int **streets;
		streets = (int **)malloc(streetsNumb * sizeof(int *));
		for(i = 0; i < streetsNumb; i++)
			streets[i] = (int *)malloc((2*(lineSegmentsNumb+1)) * sizeof(int));

		for(i = 0; i < streetsNumb; i++){
			for(j = 0; j < 2*(lineSegmentsNumb+1); j += 2){
				bool err = 0;
				do{
					attempts++;
					xtmp = randGenerator(coordinatesRange);//check error
					ytmp = randGenerator(coordinatesRange);
					err = errorCheck(i, j, xtmp, ytmp, streets, lineSegmentsNumb);
				} while(err == 1 && attempts < attemptsBound);
				if(err == 0){
					streets[i][j] = xtmp;//add temp to streets if there is no error
					streets[i][j+1] = ytmp;
				}
				else if(err == 1){
					fprintf(stderr, "Error: failed to generate valid input for %d simultaneous attempts.\n", attemptsBound);
					int K;
					for(k = 0; k < streetsNumb; k++)
						free(streets[k]);
					free(streets);
					exit(0);

				}
			}
		}

		for(i = 0; i < streetsNumb; i++){
			printf("a \"%d\" ", i);
			j = 0;
			while(j < 2*(lineSegmentsNumb+1)){
				printf("(%d,", streets[i][j]);
				j++;
				printf("%d) ", streets[i][j]);
				j++;
                        }
			printf("\n");
                }
		printf("g\n");

		for(i = 0; i < streetsNumb; i++)
  			free(streets[i]);
  		free(streets);
		fflush(stdout);
		sleep(waitingTime);


	}
	return 0;
}