/*----------------------------------------------------------------------- * gen_probleme * * Génértateur de positions aléatoires * * Auteur : Alexandre AUPETIT (aaupetit@club-internet.fr) * Web : http://home.alex.tuxfamily.org/pvc.html * http://home.alex.tuxfamily.org/pvc/robotique/coconut.html * * Important : Ce logiciel est soumis à la licence de logiciel libre GPL *-----------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <string.h> #define XMIN -6 #define XMAX -1 #define YMIN 2 #define YMAX 6 // initialisation de la position des balles par lecture du fichier pos.txt // le fichier pos_balles.txt doit contenir les positions au format : // x_robot;y_robot // x_balle1;y_balle1 // x_balle2;y_balle2 // x_balle3;y_balle3 // ... // x_balle8;y_balle8 void write_pos(int nb_balles) { FILE *ficPos; double x, y; int i; ficPos=fopen("pos_balles.txt", "w+"); fprintf(ficPos, "-0.5;0.5\n"); if (ficPos != NULL) { for (i=0; i<nb_balles; i++) { x=(double)(rand()/(RAND_MAX+1.0))*(XMAX-XMIN)+XMIN; y=(double)(rand()/(RAND_MAX+1.0))*(YMAX-YMIN)+YMIN; fprintf(ficPos, "%lf;%lf\n", x, y); } } else { printf("Erreur d'ecriture du fichier pos_balles.txt !"); exit(1); } } // ---------------------------------------------------------------------------- // prog principal // ---------------------------------------------------------------------------- int main(int argc, char *argv[]) { int nb_balles, seed; if (argc == 3) { nb_balles=atoi(argv[1]); seed=atoi(argv[2]); } else { if (argc == 2) { nb_balles=atoi(argv[1]); seed=time (NULL); } else { printf("Erreur dans le nombre d'arguments !\n"); printf("Usage : gen_probleme [Nb balles] [Graine srand]\n"); exit(1); } } srand(seed); write_pos(nb_balles); }