Ejemplo n.º 1
0
int main (int argc, const char * argv[]) {    
    int *selected_startpos = NULL;
    int num_startpos = 0;
    unsigned int num_results = 0;
    
    combset *allcombs = NULL; // all combinations
    combset_tree *resulttree_root; // result tree
    
    // handle parameters
    if (argc < 3) {
        printf("Usage: %s <no_players> <no_tables> [autostop=0] [startpositions]\n", argv[0]);
        return 1;
    } else {
        // N_PLAYERS
        N_PLAYERS = atoi(argv[1]);
        N_TABLES = atoi(argv[2]);
        
        if (N_PLAYERS % N_TABLES != 0) {
            printf("Unable to arrage all players. All tables must have same amount of players.\n");
            return 1;
        }
        N_PPT = N_PLAYERS / N_TABLES;
    }
    
    // save autostop
    if (argc > 3) {
        autostop = atoi(argv[3]);
    }
    
    if (argc > 4) {
        init_positions(&selected_startpos, argc-4);
        int i;
        // save all selected start positions
        for (i = 0; i < argc-4; i++) {
            selected_startpos[i] = atoi(argv[i+4]);
            num_startpos++;
        }
    }
    
    // init
    init_combset(&allcombs);
    init_combset_tree(&resulttree_root);
    
    // Build all possible combinations
    build_all_comb(allcombs);
    
    // fill first level
    if (num_startpos > 0) {
        find_all_round_combsets(allcombs, resulttree_root, selected_startpos[0]);
    } else {
        find_all_round_combsets(allcombs, resulttree_root, -1);
    }
    
    find_all_subcombsets(resulttree_root, allcombs, selected_startpos, num_startpos, &num_results);
    
    printf("results total: %u\n", num_results);
    
    return 0;
}
Ejemplo n.º 2
0
int main()
{
	init(); 
	init_positions(); 
	init_buttons(); 

	while(1)
	{		
		if(ButtonPressed(BUTTON3, PA2))
		{
			change_mode(); 
		}
		
		process_mode(currentMode); 
	} 

	return 0; 
}
Ejemplo n.º 3
0
int find_all_round_combsets(combset *worker, combset_tree *parent, int pos_limit)
{
    int *positions;
    combset_tree *temp;
    int counter = 0;
    
    // init
    init_positions(&positions, N_TABLES);
    init_combset_tree(&temp);
    
    // find next combset and append to tree
    while (find_next_round_combset(temp->round, worker, positions, 0) == 1) {
        // append only if position limitation is reached or deactivated
        if (pos_limit == -1 || counter == pos_limit) {
            append_combset_tree_child(parent, temp);
            
            // re-initialize temp
            init_combset_tree(&temp);
            
            // break if position has reached 
            if (counter == pos_limit) { break; }
        } else {
            destroy_combset_tree_element(temp);
            
            // re-initialize temp
            init_combset_tree(&temp);
        }
        

        
        counter++;
    }
    
    if (pos_limit > counter) {
        printf("selected position out of range\n");
    }
    
    // clean memory
    destroy_combset_tree_element(temp);
    destroy_positions(positions);
    
    return counter;
}
Ejemplo n.º 4
0
void fly(perfobj_t *viewer_pos)
{
	float       terrain_z, xpos, ypos, xcntr, ycntr;
	float       delta_speed = .003;

/*	if (++_frame == 1000) {
		_frame = 0;
		init_positions();
		}*/

    xcntr = Wxsize / 2;
    ycntr = Wysize / 2;

    if (Xgetbutton(RKEY))
        init_positions();

    if (Xgetbutton(SPACEKEY)) {
        Keyboard_mode = !Keyboard_mode;
    }

	if (Keyboard_mode) {

        /*
         * step-at-a-time debugging mode
         */

        if (Keyboard_mode && Xgetbutton(LEFTARROWKEY)) {
			Azimuth -= 0.025;
		}
		if (Keyboard_mode && Xgetbutton(RIGHTARROWKEY)) {
			Azimuth += 0.025;
		}
		if (Keyboard_mode && Xgetbutton(UPARROWKEY)) {
			X += cosf(-Azimuth + M_PI / 2.) * 0.025;
			Y += sinf(-Azimuth + M_PI / 2.) * 0.025;
		}
		if (Keyboard_mode && Xgetbutton(DOWNARROWKEY)) {
			X -= cosf(-Azimuth + M_PI / 2.) * 0.025;
			Y -= sinf(-Azimuth + M_PI / 2.) * 0.025;
		}
		if (Keyboard_mode && Xgetbutton(PAGEUPKEY)) {
			Z += 0.025;
        }
        if (Keyboard_mode && Xgetbutton(PAGEDOWNKEY)) {
            Z -= 0.025;
        }

    } else {

        /*
         * simple, mouse-driven flight model
         */

        if (Xgetbutton(LEFTMOUSE) && Speed < .3)
            Speed += delta_speed;
        if (Xgetbutton(RIGHTMOUSE) && Speed > -.3)
            Speed -= delta_speed;
        if (Xgetbutton(MIDDLEMOUSE))
            Speed = Speed*.8;

        xpos = (Xgetvaluator(MOUSEX)-xcntr) / ((float)Wxsize*14.);
        ypos = (Xgetvaluator(MOUSEY)-ycntr) / ((float)Wysize*.5);

        /*
         * move in direction of view
         */

        Azimuth += xpos;
        X += cosf(-Azimuth + M_PI / 2.) * Speed;
        Y += sinf(-Azimuth + M_PI / 2.) * Speed;
        Z -= ypos * Speed;
    }

    /*
     * keep from getting too close to terrain
     */

    terrain_z = terrain_height(X, Y);
    if (Z < terrain_z +.4)
        Z = terrain_z +.4;

    X = MAX(X, 1.);
    X = MIN(X, GRID_RANGE);
    Y = MAX(Y, 1.);
    Y = MIN(Y, GRID_RANGE);
    Z = MIN(Z, 20.);

    *((float *) viewer_pos->vdata + 0) = X;
    *((float *) viewer_pos->vdata + 1) = Y;
    *((float *) viewer_pos->vdata + 2) = Z;
    *((float *) viewer_pos->vdata + 3) = Azimuth;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[]){
    int maxTotal;
    int numCorners,numBorders,numCenters;
    int perc_shake_border=0;
    int perc_shake_center=0;
    int perc_shake_coner=0;
    int width;
    int heigth;
    int corners [4];
    int *borders;
    int *centers;
    pos_t pos_corners[4];
    pos_t *pos_borders;
    pos_t *pos_centers;
    int currBestScore=0,bestScore=BEST_SCORE;

    int fine=0;
    int p=1;
    int levelMax=LEVEL_MAX;
    int stepStarts=0;

    int iterMax = ITER_MAX;
    clock_t start,stop;
    float difference;


    switch(argc){
       case 5:
                if ( argv[1][1] == 't')
                    sscanf(argv[2],"%d", &maxTime);
                else if ( argv[1][1] == 'p')
                      sscanf(argv[2],"%d", &maxScore);
                else{
                    printf("Option not valid\n");
                    goto error;
                }
                FILE_IN = strdup(argv[3]);
                FILE_OUT = strdup(argv[4]);
                break;
        case 7:
                if ( argv[1][1] == 't')
                    sscanf(argv[2],"%d", &maxTime);
                else{
                    printf("Option not valid\n");
                    goto error;
                }
                if ( argv[3][1] == 'p')
                      sscanf(argv[4],"%d", &maxScore);
                else{
                    printf("Option not valid\n");
                    goto error;
                }
                FILE_IN = strdup(argv[5]);
                FILE_OUT = strdup(argv[6]);
                break;
        default:
             error: printf("\nUSAGE: %s [-t <time in seconds>] [-p <maximum score>] <input file> <output file>\n",argv[0]);
             return 0;
    }

    srand(time(NULL));
    parser(corners,&borders,&centers,&vector,&width,&heigth);

    numCorners=4;
    numBorders=2*(heigth-2)+2*(width-2);
    numCenters=(heigth-2)*(width-2);
    pos_borders= (pos_t *) malloc( numBorders*sizeof(pos_t) );
    pos_centers= (pos_t*) malloc(numCenters*sizeof(pos_t));
    init_positions(pos_corners,pos_borders,pos_centers,width,heigth);
    maxTotal=heigth*(width-1)+width*(heigth-1);
    printf("Max Total: %d\n",maxTotal);

    elem_sol **currBest,**best;
    currBest=allocaMatrix(width,heigth);
    best=allocaMatrix(width,heigth);
    elem_sol**neighborOfcurrBest;
    neighborOfcurrBest=allocaMatrix(width,heigth);

    globalTime=clock();
    while (!fine){
        stepStarts++;
        start=clock();
        stop=clock();
        difference=(float)(stop-globalTime)/CLOCKS_PER_SEC;
        printf("\nGlobal Time %.2f Start %d - global best %d\n",difference,stepStarts,bestScore);
        //leggiFile(vector,currBest,width,heigth);
        generateRandomSolution(currBest,vector,corners,borders,centers,width,heigth);
        currBestScore=CheckMatchingEdgesSol(currBest,width,heigth);
        //printGame(heigth, width, currBest);
        //printf ("parto da %d \n", currBestScore);

        p=LEVEL_MIN;
        fine=improve(0,start,p,levelMax,iterMax,&currBestScore,&bestScore,currBest,width,heigth,pos_centers,pos_borders,pos_corners,
        numCenters,numBorders,numCorners,perc_shake_coner,perc_shake_border,perc_shake_center,maxTotal,best,stepStarts,MAX_UGUALE);

        //printGame(heigth, width, currBest);
        if ( currBestScore > bestScore ){
            storeSolution(best,currBest,width,heigth);
            bestScore=currBestScore;
            //stop = clock();
            //difference = (stop - start)/CLOCKS_PER_SEC;
            //printf ("\nBEST edges matching = %d \t tempo: %f\n", bestScore, difference);
            //printGame(heigth, width,best);
            printer(width,heigth,best);
        }
    }
    freeThings(currBest, best, neighborOfcurrBest, pos_borders, pos_centers, borders, centers, vector, heigth);
    return 0;
}