int launch_party(char **tab, int nb_col, int nb_line) { while (!test_end(tab, nb_col, nb_line)) { get_player(tab, nb_col); print_tab(tab, nb_col, nb_line); if (test_end(tab, nb_col, nb_line)) return (0); get_computer(tab, nb_col); print_tab(tab, nb_col, nb_line); } return (0); }
int main(int argc, char **argv) { char **tab; int nb_line; int nb_col; if (argc != 3 || !test_arg(argv[1], argv[2])) { ft_printf("%rBad usage: puissance4 <nb_line> <nb_column>\n"); return (1); } nb_line = ft_atoi(argv[1]); nb_col = ft_atoi(argv[2]); if (nb_line < 6 || nb_col < 7) { ft_printf("%rBad usage, col < 7 or line < 6\n"); return (1); } if ((tab = get_tab(nb_line, nb_col)) == NULL) { ft_printf("%rAllocation Fail\n"); return (1); } print_tab(tab, nb_col, nb_line); launch_party(tab, nb_col, nb_line); free_tab(tab); return (0); }
int launcher(t_box *box) { char buf[1]; int dir; jump; ft_putstr("\033[35mWHICH DIRECTION FOR THE NEXT MOVE ? :\033[0m"); jump; while (read(0, buf, sizeof(buf))) { if (!(dir = check(buf))) continue ; if (dir == 2) turn_right(box); if (dir == 1) turn_left(box); if (dir == 3) turn_up(box); if (dir == 4) turn_down(box); ft_putstr("YOUR SCORE IS : "); ft_putnbr(box->score); jump; jump; ft_putstr("\033[35mAND NOW ? : \033[0m"); jump; init(box, (ft_random((box->size * box->size), 0))); print_tab(box); } return (0); }
int main(){ int key, value, i; int htab[M] = {0}; begin: printf("Insert elements to the hash table...\n"); for(i=0; i<M; i++){ printf("Enter value(-1 to stop): "); scanf("%d", &value); if(value == -1) break; insert(htab, hash(value), value); } //Display table print_tab(htab); //Search printf("Search value: "); scanf("%d",&value); if(value != -1) { key = search(htab, value); printf("htab[%d] = %d\n", key, htab[key]); } char opt; flush_stdin(); printf("Do you want to begin again? (y/n): "); scanf("%c", &opt); if(opt == 'y') goto begin; else if(opt != 'n') printf("Wrong option!!! But still.... Bye!!!\n"); return 0; }
static void visit(struct task *p) { struct task *next; static int tab = 0; unsigned int i; #define print_tab() for (i = 0; i < tab; i++) puts("|\t"); print_tab(); printf("+-- 0x%x 0x%02x 0x%02x %d\n", p->addr, get_task_type(p), get_task_state(p), get_task_pri(p)); print_tab(); printf("| /vruntime %d /exec_runtime %d (%d sec)\n", (unsigned)p->se.vruntime, (unsigned)p->se.sum_exec_runtime, (unsigned)p->se.sum_exec_runtime / HZ); print_tab(); printf("| /sp 0x%08x /base 0x%08x /heap 0x%08x /size %d\n", p->mm.sp, p->mm.base, p->mm.heap, STACK_SIZE); print_tab(); printf("| /kernel stack 0x%08x base 0x%08x\n", p->mm.kernel.sp, p->mm.kernel.base); print_tab(); printf("|\n"); if (list_empty(&p->children)) return; tab++; next = get_container_of(p->children.next, struct task, sibling); visit(next); p = next; while (p->sibling.next != &p->parent->children) { next = get_container_of( p->sibling.next, struct task, sibling); visit(next); p = next; } tab--; printf("control %08x, sp %08x, msp %08x, psp %08x\n", GET_CNTL(), GET_SP(), GET_KSP(), GET_USP()); }
/*array' -> element-list ] | ]*/ void arrayB_trad(){ if(t.compLex == L_CORCHETE || t.compLex == L_LLAVE){ printf("\n"); print_tab(); printf("<item>\n"); tabulacion+=4; element_list_trad(); match(R_CORCHETE); print_tab(); printf("</item>\n"); } else if(t.compLex == R_CORCHETE){ tabulacion-=4; match(R_CORCHETE); } }
static void print_rc(wtreeNode_t* parent, int depth) { if (!parent) return; print_rc(parent->right, depth + 1); print_tab(depth); PRINT("Node@%lx (bottom : %lx / base :%lx) {size : %u / base_size : %u / top : %lx} (%d)\n", (uint64_t) parent, (uint64_t)parent->top - parent->size, (uint64_t)parent->top - parent->base_size, parent->size, parent->base_size, (uint64_t) parent->top, depth); print_rc(parent->left, depth + 1); }
void text_scope(unsigned long cycles, int voice, enum PaulaEventType e, int value) { unsigned int sec = cycles / SOUNDTICKS; unsigned int usec = ((uint64_t) (cycles % SOUNDTICKS) * 1000000) / SOUNDTICKS; printf("%6u:%.6u ", sec & 0x1ffff, usec); print_tab(voice); printf("%s %5d %d\n", PaulaEventStr[e], value, voice); }
/*element-list' -> ,element element-list' | ε*/ void element_listB_trad(){ if(t.compLex == R_CORCHETE){ //tabulacion-=4; return; } if(t.compLex == COMA){ match(COMA); // tabulacion-=4; print_tab(); printf("</item>\n"); print_tab(); printf("<item>\n"); tabulacion+=4; element_trad(); element_listB_trad(); } }
/* attribute -> attribute-name : attribute-value*/ void attribute_trad(){ if(t.compLex == LITERAL_CADENA){ print_tab(); char lexema[TAMLEX]; strcpy(lexema,t.lexema); printf("<"); attribute_name_trad(); printf(">"); match(DOS_PUNTOS); attribute_value_trad(); printf("</"); string_sin_comillas(lexema); printf(">\n"); } }
int fib_rek(int liczba,int depth) { static int tab[255]; static int l=0; l++; print_tab(depth); if(liczba==1) { printf("Zwracam f(%d), l=%d\n",1,l); return 1; }; if(liczba==2) { printf("Zwrafam f(%d), l=%d\n",2,l); return 1; }; /* if(liczba==3) { printf("Zwracam f(%d), l=%d\n",2,l); return 2; }; */ printf("Obliczam f(%d), l=%d\n",liczba,l); if(tab[liczba]) { print_tab(depth); printf("Zwracam f(%d), l=%d\n",liczba,l); return tab[liczba]; }; if(!tab[liczba-1]) tab[liczba-1]=fib_rek(liczba-1,depth+1); if(!tab[liczba-2]) tab[liczba-2]=fib_rek(liczba-2,depth+1); print_tab(depth); printf("zwracam f(%d), l=%d\n",liczba,l); return tab[liczba-1]+tab[liczba-2]; };
int check_alias(char *cmd, char **alias) { char *sauv; int i; i = 0; if ((strncmp(cmd, "alias", 5)) == 0) print_tab(alias); else while (alias[i] != NULL) { sauv = my_strcat("alias ", cmd); if ((strncmp(sauv, alias[i], strlen(sauv))) == 0) return (i); i++; } return (-1); }
int main(){ //Hash table Head_ptr htab[M]={NULL}; int i, value; begin: //Initialize hash table to NULL for(i=0; i<M; i++){ //htab[i] = NULL; } //Insert printf("Insert values...\n"); while(1){ printf("Enter a value(-1 to stop): "); scanf("%d", &value); if(value == -1) break; if(insert(htab, value) == -1){ fprintf(stderr, "Error: Insertion failed1\n"); continue; } } //Display print_tab(htab); //Search for values while(1){ Node *s_addr; printf("\nEnter a value to search(-1 to stop): "); scanf("%d", &value); if(value == -1) break; if((s_addr=search(htab, value)) == NULL){ fprintf(stderr, "Error: Value not found!\n"); continue; } printf("Value %d was found at %dth location in htab, and the node address is %u\n", value, hash(value), (unsigned)s_addr); } return 0; }
int main() { int tab[N]; srand(time(NULL)); for (int i = 0; i < N; i++) { tab[i] = rand() % (VALUE_MAX * 2) - VALUE_MAX; } printf("Tableau : "); print_tab(tab, N); printf("\n\n"); printf(" Comp Assign Seconds uSeconds\n"); measure_sort("Selection Sort", tab, &selection_sort); measure_sort("Insertion Sort", tab, &insertion_sort); measure_sort("Quick Sort (F)", tab, &quick_sort_first); measure_sort("Quick Sort (R)", tab, &quick_sort_random); //measure_sort("Bubble Sort ", tab, &bubble_sort); return 0; }
void opt_r_and_null(DIR *rep, char *opt, int id) { int a; struct dirent *list; char **tab; a = 0; tab = (char**)malloc(sizeof(char*)); while ((list = readdir(rep))) { tab[a] = list->d_name; a++; } a -= 1; swap(tab); if (opt != NULL && (id == 1 || id == 3)) a = 0; print_tab(tab, id, a); free(tab); }
int main(int ac, char **av) { char **tab; if (ac != 4){ my_putstr("wrong parameter number\n"); my_putstr("usage : lenght hight cell number\n"); return (0); } if ((my_getnbr(av[1]) * my_getnbr(av[2])) < my_getnbr(av[3])){ my_putstr("please enter a correct amount of cell (too big)\n"); return (0); } my_pars_args(av, 0); if ((tab = my_tab_remp(av, 0)) == NULL) return (0); tab[my_getnbr(av[2]) + 2] = NULL; tab = my_rand_star(my_getnbr(av[3]), tab, av); print_tab(tab); algo(tab, av); return (0); }
int main(void) { get_signal(); get_custom_win_value(); if (!is_a_good_win_value(g_info.win_condition)) ft_win_value_error(g_info.win_condition); // get_custom_x_y_value(); init_tab(); set_to_zero_tab(); start_random_nb_to_tab(); initscr(); keypad(stdscr, TRUE); noecho(); timeout(0); print_tab(); while (1) { is_a_valid_key(getch()); } endwin(); return (0); }
int main(int argc, char **argv) { int **tab; int **tab_rev; tab = alloc_tab(); tab_rev = alloc_tab(); if (argc != 10) return (throw_error()); if (!populate_tab(tab, argc, argv)) return (0); populate_tab(tab_rev, argc, argv); find_solution(tab, 0, 0, 0); find_solution(tab_rev, 0, 0, 1); if (compare_solution(tab, tab_rev)) print_tab(tab); else ft_putstr("Erreur\n"); free_tab(tab); free_tab(tab_rev); return (0); }
int main(int ac, char **av) { t_win win; int **tab; t_screen s_size; if (ac != 2) { ft_putendl("usage : fdf [file]"); exit(1); } if (!(tab = parse(av[1]))) { ft_putendl("error parse"); return (1); } print_tab(tab, av[1]); gt_screen_size(av[1], tab, &s_size); if (!(win.mlx_ptr = mlx_init())) { ft_putstr("error init"); return (2); } if (!(win.win_ptr = mlx_new_window(win.mlx_ptr, s_size.x, s_size.y, "yolo"))) { ft_putstr("error new window"); return (3); } win.tab = tab; win.s_x = s_size.x; win.s_y = s_size.y; win.nb_line = count_nb_line(av[1]); win.nb_col = count_nb_col(av[1]); mlx_expose_hook(win.win_ptr, draw, &win); mlx_key_hook(win.win_ptr, keyboard, &win); mlx_loop(win.mlx_ptr); return (0); }
void doerror(char *ptr) { int k; gen_comment (); output_string (line); newline (); gen_comment (); k = 0; while (k < lptr) { if (line[k] == 9) print_tab (); else output_byte (' '); k++; } output_byte ('^'); newline (); gen_comment (); output_string ("****** "); output_string (ptr); output_string (" ******"); newline (); }
int main ( int argc, char *argv[] ) { int id; int ierr; int p=3; double wtime = 0, total; int n,m, bad_edges=0, oriented=0, i, diameter, leftover, lines; int **tab; int print = 0; char FILENAME[100]; int *process_lines, *process_start; /******************** MPI Initialisation *************************/ ierr = MPI_Init ( &argc, &argv ); if(ierr != MPI_SUCCESS) { perror("Error with initializing MPI"); exit(1); } // Get the number of processes. ierr = MPI_Comm_size ( MPI_COMM_WORLD, &p ); // Get the individual process ID. ierr = MPI_Comm_rank ( MPI_COMM_WORLD, &id ); /******************** Problem Initialisation *************************/ // Process 0 reads data + prints welcome n = 0; if (id==0) { for(i=1; i<argc; i++) { if(!strcmp(argv[i], "-print")) { print = 1; } else if (!strcmp(argv[i], "-read")) { strcpy(FILENAME, argv[i+1]); i++; } else if (!strcmp(argv[i], "-random")) { n = atoi(argv[i+1]); oriented = atoi(argv[i+2]); i+=2; } else { n = 4000; oriented = 1; } } if (n>0) init_tab(n,&m,&tab,oriented); // last one = oriented or not ... else bad_edges = read_tab(FILENAME, &n, &m, &tab, &oriented); fprintf(stderr, "Running program with %d rows and %d edges (%d are bad)\n", n, m, bad_edges); fprintf(stderr, "The number of processes is %d.\n", p); } // Distribute the problem size to all machines MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); // Malloc the table, which was not yet done for the other processes if(id != 0) malloc_tab(n, &tab); // Distribute the table to all machines. for(i = 0; i < n; i++) MPI_Bcast(tab[i], n, MPI_INT, 0, MPI_COMM_WORLD); // Determine the lines and start per process process_lines = malloc(p * sizeof(int)); process_start = malloc(p * sizeof(int)); leftover = n % p; lines = n / p; for(i = 0; i < p; i++) { process_lines[i] = i < leftover ? lines + 1 : lines; process_start[i] = i * lines + (i < leftover ? i : leftover); } printf("%d - Pointers: %d & %d\n", id, (int)process_lines, (int)process_start); /******************** Distance calculation *************************/ MPI_Barrier(MPI_COMM_WORLD); if(id == 0) wtime = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); printf("%d - Pointers: %d & %d\n", id, (int)process_lines, (int)process_start); total = do_dist(tab, n, id, p, process_start, process_lines); printf("%d - Pointers: %d & %d\n", id, (int)process_lines, (int)process_start); if(id == 0) { wtime = MPI_Wtime() - wtime; fprintf (stderr, "Distance took %10.3f seconds.\n", wtime); } /******************** ASP *************************/ MPI_Barrier(MPI_COMM_WORLD); if(id == 0) wtime = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); //do_asp(tab, n, id, p, process_start, process_lines); do_asp_lin(tab, n, id, p, process_start, process_lines); if(id == 0) { wtime = MPI_Wtime() - wtime; fprintf (stderr, "ASP took %10.3f seconds.\n", wtime); } /******************** Diameter *************************/ MPI_Barrier(MPI_COMM_WORLD); if(id == 0) wtime = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); diameter = do_diam(tab, n, id, p, process_start, process_lines); if(id == 0) { wtime = MPI_Wtime() - wtime; fprintf (stderr, "Diameter took %10.3f seconds.\n", wtime); } if(id == 0 && print == 1) { print_tab(tab, n); printf("Total distance: %.0lf\n", total); printf("Diameter: %d\n", diameter); } // Clean up free_tab(tab, n); free(process_start); free(process_lines); // Shut down MPI. ierr = MPI_Finalize(); return 0; }
int main(int argc, char* argv[]) { srand(time(NULL)); previoustime = 0; previoustime_deaths = currenttime; previoustime_creation_enemies = -10000; previoustime_bonus = -15000; time_bouclier = -5000; previoustime = currenttime; Uint8 *key = SDL_GetKeyState(NULL); /* initialize video system */ SDL_Init(SDL_INIT_VIDEO); /* set the title bar */ SDL_WM_SetCaption("SDL Move", "SDL Move"); /* create window */ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0); /*begin*/ printf("Appuyez sur Entrée pour commencer la partie\n"); temp = SDL_LoadBMP("debut.bmp"); wall = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); while (!begin) { if (SDL_PollEvent(&event)) { HandleEvent(event); } SDL_BlitSurface(wall, NULL, screen, &imWall); SDL_UpdateRect(screen,0,0,0,0); } /* load sprite */ temp = SDL_LoadBMP("salameche.bmp"); spritetemp = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); perso = sprite_cons(0, 362, 110, 0, spritetemp, colorkey, 5, NULL, 's', 5, 22); temp = SDL_LoadBMP("heart.bmp"); heart = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); SDL_SetColorKey(heart, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); bonus_vie = sprite_cons(rand()%(LEVEL_WIDTH-16), rand()%(LEVEL_HEIGHT/2-16)+LEVEL_HEIGHT/2, 0, 0, heart, colorkey, 0, NULL,'b', 0, 16); temp = SDL_LoadBMP("abri.bmp"); abri = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); SDL_SetColorKey(heart, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); bonus_abri = sprite_cons(rand()%(LEVEL_WIDTH-40), rand()%(LEVEL_HEIGHT/2-40)+LEVEL_HEIGHT/2, 0, 0, abri, colorkey, 0, NULL,'b', 0, 40); /*temp = SDL_LoadBMP("lanceflamme.bmp"); lance_flamme = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); SDL_SetColorKey(heart, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); bonus_lf = sprite_cons(rand()%(LEVEL_WIDTH-47), rand()%(LEVEL_HEIGHT/2-8)+LEVEL_HEIGHT/2, 0, 0, lance_flamme, colorkey, 7, NULL,'b', 0, 30);*/ temp = SDL_LoadBMP("bloc.bmp"); stone1 = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); temp = SDL_LoadBMP("bloc2.bmp"); stone2 = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); temp = SDL_LoadBMP("bloc3.bmp"); stone3 = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); /* load wall */ temp = SDL_LoadBMP("fond.bmp"); wall = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); /* set wall position */ imWall.x = 0; imWall.y = 0; gameover = 0; /* message pump */ currenttime2 = SDL_GetTicks(); int nb_enemies, randnumber; while (!gameover) { currenttime = SDL_GetTicks(); if (SDL_PollEvent(&event)) { HandleEvent(event); } if (currenttime - currenttime2 > 50){ currenttime2 = currenttime; MultiEvent(key); //apparition ennemis if (currenttime - previoustime_creation_enemies > delta_creation_enemies && niveau !=3) { for (nb_enemies = 0; nb_enemies < 5; nb_enemies = nb_enemies +1) { randnumber = rand()%3; if (randnumber == 0) { temp = SDL_LoadBMP("taupi.bmp"); spritetemp = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); list_enemy = cons(sprite_cons(rand()%(LEVEL_WIDTH-22),rand()%(LEVEL_HEIGHT-22), 0, 0, spritetemp, colorkey, 0, NULL, 't', 2, 22),list_enemy); } else if (randnumber == 1) { temp = SDL_LoadBMP("cara.bmp"); spritetemp = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); list_enemy = cons(sprite_cons(rand()%(LEVEL_WIDTH-25),rand()%(LEVEL_HEIGHT-25), 0, 0, spritetemp, colorkey, -3, NULL, 'c',2, 25),list_enemy); } else { temp = SDL_LoadBMP("meta.bmp"); spritetemp = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); colorkey = SDL_MapRGB(screen->format, 0, 255, 255); list_enemy = cons(sprite_cons(rand()%(LEVEL_WIDTH-20),rand()%(LEVEL_HEIGHT-20), 0, 0, spritetemp, colorkey, -5, NULL, 'm',2, 20),list_enemy); } test_apparition(first_of(list_enemy)); } previoustime_creation_enemies = currenttime; } // test arret gauche if (pasgauche && !pasdroit) { arret_gauche(perso); pasgauche = false; } // test arret droit if (pasdroit && !pasgauche) { arret_droit(perso); pasdroit = false; } // saut if (jump) { jump_perso(perso); } else { //gravitation i = (perso -> imSprite.x + perso -> posSprite.h/2)/32; j = (perso -> imSprite.y + perso -> posSprite.h +vy)/32; surbloc = tab_blocs[j][i] != 0; sursol = perso ->imSprite.y == 383 - perso -> posSprite.h ; if (!surbloc && perso->imSprite.y < 361) { vy = 7; perso->imSprite.y += vy; } j = (perso -> imSprite.y + perso -> posSprite.h + vy)/32; surbloc = tab_blocs[j][i] != 0; sursol = perso->imSprite.y >= 361; if (surbloc && !sursol) { perso->imSprite.y = j*32 - perso->posSprite.h; } if (sursol) { perso->imSprite.y = 361; } } //bonus if (currenttime - previoustime_bonus > 15000 && currenttime-time_bouclier>=5000) { placement_bonus(); } if (collision(perso, bonus_vie)) { deaths = deaths - 1; bonus_vie->imSprite.x = LEVEL_WIDTH + 1; previoustime_bonus = currenttime; } if (currenttime-time_bouclier >= 5000 && immunite){ bonus_abri->imSprite.x = LEVEL_WIDTH + 1; immunite = false; } if (collision(perso, bonus_abri)) { bonus_abri->imSprite.x = perso->imSprite.x - (45 - perso->posSprite.h)/3; bonus_abri->imSprite.y = perso->imSprite.y - (45 - perso->posSprite.h)/3; if (!immunite){ time_bouclier = currenttime; } immunite = true; } else { immunite = false; } move_enemy(list_enemy, list_fire_enemy); positionfire(list_fire); list_enemy = list_enemy_destruction (list_fire, list_enemy, &list_fire_enemy, camera); list_fire = list_fire_destruction (list_fire, camera); list_fire_enemy = list_fire_destruction (list_fire_enemy, camera); level_2(); level_3(); } if (currenttime - previoustime_deaths > 1000){ death_temp = deaths; deaths = collision_enemy(list_enemy, perso, deaths, camera); if (death_temp != deaths){ previoustime_deaths = currenttime; } } Setcamera(); SDL_BlitSurface(wall, NULL, screen, &imWall); print_tab (tab_blocs, camera); printlist (list_enemy); imCamera = Calculposition(bonus_vie ->imSprite.x, bonus_vie ->imSprite.y, camera); SDL_BlitSurface(bonus_vie -> spr, &bonus_vie -> posSprite, screen, &imCamera); imCamera = Calculposition(bonus_abri ->imSprite.x, bonus_abri ->imSprite.y, camera); SDL_BlitSurface(bonus_abri -> spr, &bonus_abri -> posSprite, screen, &imCamera); /* draw the sprite */ imCamera = Calculposition(perso ->imSprite.x, perso ->imSprite.y, camera); if (imCamera.x < 0) { imCamera.x = 0; perso -> imSprite.x = 0; } if (imCamera.x > SCREEN_WIDTH-22) { imCamera.x = SCREEN_WIDTH-22; perso -> imSprite.x = LEVEL_WIDTH-22; } SDL_BlitSurface(perso -> spr, &perso ->posSprite, screen, &imCamera); printlist(list_fire); printlist(list_fire_enemy); heart_pos.x = 0; for (i = 0; i < 5 - deaths; i = i+1) { SDL_BlitSurface(heart, NULL, screen, &heart_pos); heart_pos.x = heart_pos.x + 17; } if (niveau==3){ if (!is_empty(list_enemy)){ heart_pos.x = 624; for (i = 0; i < first_of(list_enemy)->life; i = i+1) { SDL_BlitSurface(heart, NULL, screen, &heart_pos); heart_pos.x = heart_pos.x - 17; } }else{ printf("BRAVO, VOUS AVEZ GAGNÉ !\n"); gameover = 1; } } if (deaths >= 5){ printf("DÉSOLÉ, VOUS AVEZ PERDU !\n"); gameover = 1; } /* update the screen */ SDL_UpdateRect(screen,0,0,0,0); SDL_Delay(5); } /* clean up */ SDL_FreeSurface(stone1); SDL_FreeSurface(stone2); SDL_FreeSurface(stone3); SDL_FreeSurface(heart); SDL_FreeSurface(screen); SDL_FreeSurface(wall); free (bonus_vie); SDL_FreeSurface(bonus_abri->spr); free (bonus_abri); SDL_FreeSurface(perso -> spr); free (perso); free_list(&list_fire); free_list(&list_enemy); SDL_Quit(); return 0; }
bool SimplexFltr::is_floater(int unitj, int sign) { bool isfltr=false; //now construct the gjs //j and i subscripts based on 7-16-15 notes convention: //j is row of tableau, i is column for(int j=0; j<d; j++) { for(int i=0; i<d; i++) { //first the unit left gsl_vector_set(gjs[j],i,j==i); } for(int i=d; i<d+c; i++) { //now put in the jth entries of each fti double entry = gsl_vector_get(ftis[i-d],j); if(j==unitj) entry*=sign;//this is (P) from notes gsl_vector_set(gjs[j],i,entry); } //now put in the unit vector component (final column) gsl_vector_set(gjs[j],d+c,j==unitj); } //now make the j==d vector (aka x) for(int i=0; i<d; i++) { //first the zeros on the left gsl_vector_set(gjs[d],i,0); } for(int i=d; i<d+c+1; i++) { //-1*sum over j of ith entries of gjs double sum=0; for(int j=0; j<d; j++) sum+=gsl_vector_get(gjs[j],i); sum*=-1; gsl_vector_set(gjs[d],i,sum); } //make bi for(int j=0; j<d; j++) { bi.at(j) = j; } /* //second test: see if initial tableau was made correctly print_tab(); //exit(0); */ //now implement actual simplex algo part int indent; //the index of the entering variable int numsteps=0;//don't let it go over 10k while((indent=entering_col())<d+c) { std::vector<std::vector<double> > rats;//ratios for simplex ratio test for(int j=0; j<d; j++) { //store ratios //denominator in ratio test double denom=gsl_vector_get(gjs[j],indent); //denom must be non-zero and non-negative if(denom>=signtol) { //store the ratio (1) and its row (0) std::vector<double> nextrat; nextrat.push_back(j); nextrat.push_back(gsl_vector_get(gjs[j],d+c)/denom); rats.push_back(nextrat); } } /* //print ratios to debug std::cout << "ratios: " << std::endl; for(int k=0; k<rats.size(); k++){ std::cout << rats[k][0] << " " << rats[k][1] << std::endl; } */ if(rats.size()==0) { std::cout << "no ratios found" << std::endl; exit(1); } std::vector<int> smallest;//rats-indices of smallest ratios smallest.push_back(0); //find the rat-indices of the smallest rat.s for(int k=1; k<rats.size(); k++) { double diff = rats[k][1]-rats[smallest[0]][1]; if(diff<-signtol) { //neg. diff means k-th rat is smaller smallest.clear(); smallest.push_back(k); } else if(std::abs(diff)<signtol) { //rats are equal smallest.push_back(k); } } int smlsml=0;//smlst-index with smlst basic variable row //find the smallest smallest (lowest basic variable col #) for(int k=1; k<smallest.size(); k++) { int current = bi[rats[smallest[smlsml]][0]]; int challenger = bi[rats[smallest[k]][0]]; if(challenger<current) smlsml=k; } pivot(rats[smallest[smlsml]][0],indent); //enter entering and leave leaving bi.at(rats[smallest[smlsml]][0])=indent; numsteps++; if(numsteps>=maxsteps) { std::cout << "max # of steps reached" << std::endl; exit(1); } //sanity check: RHS should always be positive for(int j=0; j<d; j++) { double rhs=gsl_vector_get(gjs[j],d+c); if(rhs<=-signtol) { //then neg. rhs entry exists->error std::cout << "negative rhs:" << std::endl; print_tab(); exit(1); } } /* //third test: see if tableau is right after i iterations print_tab(); //exit(1); */ } //bottom right corner of the tableau is the value of the obj. fxn. double objfxn = gsl_vector_get(gjs[d],d+c); if(objfxn>signtol) { //objective fxn should never go positive std::cout << "objective function somehow positive" << std::endl; exit(1); } if(objfxn<-signtol) { //not a floater iff objfxn is zero isfltr=true; } return isfltr; }
void print_alias(char **alias) { print_tab(alias); return ; }
int main(int argc, char *argv[]) { const char* optstring = ":ha:p:P:ld:D:"; const struct option lopts[] = { {"help", no_argument, NULL, 'h'}, {"appartient", required_argument, NULL, 'a'}, {"positions", required_argument, NULL, 'p'}, {"phrases", required_argument, NULL, 'P'}, {"liste", no_argument, NULL, 'l'}, {"prefixe", required_argument, NULL, 'd'}, {"tofile", required_argument, NULL, 'D'}, {NULL, no_argument, NULL, 0} }; int val,index=-1; int last_val = val; char* last_optarg; while (EOF!=(val=getopt_long(argc,argv,optstring,lopts,&index))) { char msg[32]; if (index==-1) sprintf(msg,"short option -%c",val); else sprintf(msg,"long option --%s",lopts[index].name); if(val == 'h') { print_help(); exit(0); } last_val = val; last_optarg = optarg; #ifdef DEBUG printf("Option %c with opt %s recieved\n", val, optarg); #endif index=-1; } Cellule tab[N]; int i = 0; for(; i<N; ++i) { tab[i].valeur = NULL; tab[i].suivant = NULL; } Liste alphab = NULL; if(argc == 1) { interactive_menu(tab, N, &alphab); exit(0); } if(optind < argc) { parse_file(tab, N, argv[optind], &alphab); if(last_val == 'a') { int res = belongs(last_optarg, tab, N); if(res) printf("Word %s is in file %s",last_optarg, argv[optind]); else printf("Word %s is not in file %s", last_optarg, argv[optind]); } else if(last_val == 'p') { print_positions(last_optarg, tab, N); } else if(last_val == 'P') { print_sentences_containing_word(last_optarg, argv[optind], tab, N); } else if(last_val == 'l') { print_alphabetical(alphab); } else if(last_val =='d') { print_all_from_prefix(last_optarg, alphab); } else if(last_val == 'D') { save_positions_to_file(last_optarg, alphab); } } else { fprintf(stderr, "Error: not enough arguments\n"); print_help(); } #ifdef DEBUG print_tab(tab, N); #endif for(i = 0; i<N; ++i) liste_free(tab[i].suivant, 0x3); liste_free(alphab, 0x0); return 0; }