void my_algo(char **tab, char **argv) { int pos; int exit; int pv; int ressource; int taille; taille = my_taille(tab); pv = my_getnbr(argv[1]); ressource = my_getnbr(argv[2]); exit = my_position(tab, '#'); pos = my_position(tab, '@'); if (exit == -1 || pos == -1) { my_putstr("La map ne contient pas d'entree ou de sortie"); return; } while (pv > 0) if (my_man(pos, exit, pv, taille) <= pv) { my_putstr("OK\n"); return; } else if (my_man(my_find_ress(tab, pos, pv, taille, exit), pos, pv, taille) <= pv) { // my_putstr("\n<--Ancien pv :"); // my_put_nbr(pv); pv = pv - my_man(my_find_ress(tab, pos, pv, taille, exit), pos, pv, taille) + ressource; // my_putstr("\nNouveau pv :"); // my_put_nbr(pv); // my_putstr("\nAncien pos :"); // my_put_nbr(pos); pos = my_find_ress(tab, pos, pv, taille, exit); // my_putstr("\nnew pos :"); // my_put_nbr(pos); my_rm_ress(tab, pos); }/* else if (my_man(my_find(tab, pos, pv, taille), pos, pv, taille) <= pv) { my_putstr("\nNew pos"); my_put_nbr(my_find(tab, pos, pv, taille)); my_putstr("\navec pv :"); my_put_nbr(pv); pv = pv - my_man(my_find(tab, pos, pv, taille), pos, pv, taille) + ressource; // my_putstr("\nNouveau pv :"); //my_put_nbr(pv); //my_putstr("\nAncien pos :"); //my_put_nbr(pos); pos = my_find(tab, pos, pv, taille); //my_putstr("\new pos :"); //my_put_nbr(pos); my_rm_ress(tab, pos); }*/ else { my_putstr("KO\n"); return; } }
int my_find_ress(char **tab, int pos, int pv, int taille, int exit) { int p; int y; int man; int real_p; int i; int j; i = 0; j = 0; y = 1000; p = 0; while (tab[i][0] != '\0') { while (tab[i][j]) { if (tab[i][j] == '+') { man = my_man(p, pos, pv, taille) + my_man(p, exit, pv, taille); if (man < y) { real_p = p; y = man; } } j++; p++; } j = 0; i++; p++; } return(real_p); }
int my_find(char **tab, int pos, int pv, int taille) { int i; int j; int p; p = 0; i = 0; j = 0; while (tab[i][0] != '\0') { while (tab[i][j]) { if (tab[i][j] == '+' && my_man(pos, p, pv, taille) <= pv) { // my_putstr("\n\nmanathan :"); // my_put_nbr(my_man(pos, p, pv, taille)); //my_putchar('\n'); return(p); } j++; p++; } j = 0; i++; p++; } return(-1); }
int check_man_echo(char **av) { if (av[1][0] == '-' && av[1][1] == 'h' && av[1][2] == '\0') { my_man("echo"); return (0); } return (-1); }