diff --git a/Labgen/a.out b/Labgen/a.out index 9afc3faa27b9fecef4426a5efd8435c6cd41ce9b..26c1cd3880170181255f8f5deff8e44319d3e462 100755 Binary files a/Labgen/a.out and b/Labgen/a.out differ diff --git a/Labgen/labgen.c b/Labgen/labgen.c index 1f520baffb831e9acd11dfd8f57041947bb0f9eb..62d4a14a4221e5fc2cdf12a4363a9667fe3018d9 100644 --- a/Labgen/labgen.c +++ b/Labgen/labgen.c @@ -1,37 +1,42 @@ #include "labgen.h" -point size; /*Attention c'est la taille réelle de la matrice*/ +Point size; /*Attention c'est la taille de l'énoncé. */ /* char *** matrice = NULL ; */ int in,out; variables listevars; -/* Crée un nouveau point de coordonnées (x,y) */ -point new_point(int x, int y) +/* Crée un nouveau point de coordonnées (c,l) + * --> Attention : l'ordre n'est pas logique (colonne, ligne) + */ +Point new_point(int c, int l) { - point monpoint; - monpoint.x = x; - monpoint.y = y; + Point monpoint; + monpoint.c = c; + monpoint.l = l; return monpoint; } /* Crée une matrice de taille (s1, s2) + * --> Attention : l'ordre n'est pas logique (colonne, ligne) + * s1 est le nombre de colonnes + * s2 est le nombre de lignes + * Implémentation de la matrice en mode naturel <------- * /!\ Attention : toujours créer la matrice avant d'utiliser * les autres fonctions */ char*** create_matrice(int s1, int s2) { int i,j; - char*** matrice = malloc((s1+1)*sizeof(char **)); + char*** matrice = malloc((s2+1)*sizeof(char **)); - for (i= 0; i<s1+1; i++){ - matrice[i] = malloc((s2+1) * sizeof(char *)); - for (j=0; j<s2+1; j++) { + for (i= 0; i<=s2; i++){ + matrice[i] = malloc((s1+1) * sizeof(char *)); + for (j=0; j<=s1; j++) { matrice[i][j] = malloc(sizeof(char)); strcpy(matrice[i][j],""); } } - size = new_point(s1+1,s2+1); - /*Attention c'est la taille réelle de la matrice*/ + size = new_point(s1,s2); in = 0; out = 0; return matrice; @@ -39,40 +44,40 @@ char*** create_matrice(int s1, int s2) /* Renvoie la valeur de la matrice de coordonnées p */ -char* lecture(point p, char*** matrice) +char* lecture(Point p, char*** matrice) { if (matrice == NULL){ printf("Matrice non initialisée.\n"); } - else if (p.x >= 0 && p.y >= 0 && p.x < size.x && p.y < size.y){ - return matrice[p.x][p.y]; + else if (p.c >= 0 && p.l >= 0 && p.c <= size.c && p.l <= size.l){ + return matrice[p.l][p.c]; } else - printf("Impossible de lire la valeur au point (%d,%d).\n", p.x,p.y); + printf("Impossible de lire la valeur au point (%d,%d).\n", p.c,p.l); return NULL; } /* void stock_val */ /* Change la valeur de la matrice de coordonnées p par la valeur msg */ -void change_val_matrice(point p, char * msg, char*** matrice) +void change_val_matrice(Point p, char * msg, char*** matrice) { if (matrice == NULL){ printf("Matrice non initialisée.\n"); } - else if (p.x >= 0 && p.y >= 0 && p.x < size.x && p.y < size.y) { + else if (p.c >= 0 && p.l >= 0 && p.c <= size.c && p.l <= size.l) { char * m1; m1 = malloc(strlen(msg)*sizeof(char)); strcpy(m1,msg); - if (matrice[p.x][p.y] != NULL){ - free(matrice[p.x][p.y]) ; + if (matrice[p.l][p.c] != NULL){ + free(matrice[p.l][p.c]) ; } - matrice[p.x][p.y] = m1; + matrice[p.l][p.c] = m1; } else { printf("Impossible de changer de valeur la valeur au point (%d,%d).\n", - p.x,p.y); + p.c,p.l); } } @@ -80,7 +85,7 @@ void change_val_matrice(point p, char * msg, char*** matrice) /*void ligne(){ int j; - for (j=0;j<size.y;j++) + for (j=0;j<size.l;j++) printf(" -------"); printf("\n"); }*/ @@ -89,8 +94,8 @@ void affichmat(char*** matrice) { int i,j; /*ligne();*/ - for(i=0;i<size.x;i++){ - for(j=0;j<size.y;j++){ + for(i=0;i<=size.l;i++){ + for(j=0;j<=size.c;j++){ printf("|%s \t",matrice[i][j]); } printf("|\n"); @@ -152,11 +157,103 @@ void create_modif_var(char* nom, int val) { } -/*int main () { - char*** matrice = create_matrice(5,4); +/* Règles sémantiques : + * Retourne 1 quand c'est correct + * Retourne 0 sinon */ - point p1 = new_point(5,4); - printf("Point p1 (%d,%d)\n",p1.x,p1.y); +/* RS1 : Le labyrinthe doit avoir au moins 2 lignes et au moins 2 colonnes */ +int RS1(Point size){ + if (size.c >= 1 && size.l >= 1) + return 1; + printf("RS1 : Le labyrinthe doit avoir au moins 2 lignes et au moins 2 colonnes.\n"); + return 0; +} + +/* RS2_count : Le labyrinthe doit avoir une et une seule entrée */ +int RS2_count(int countE){ + if (countE == 1) + return 1; + printf("RS2 : Le labyrinthe doit avoir une et une seule entrée.\n"); + return 0; +} + +/* RS2_check : L'entrée ne peut être ni une sortie ni une entrée de trou de vers */ +int RS2_check(){ + /* A faire */ + return 0; +} + +/* RS3_count : Le labyrinthe doit avoir au moins une sortie */ +int RS3_count(int countS){ + if (countS >= 1) + return 1; + printf("RS3 : Le labyrinthe doit avoir au moins une sortie.\n"); + return 0; +} + +/* RS3_check : La sortie ne peut être ni l'entrée ni une entrée de trou de vers */ +int RS3_check(){ + /* A faire */ + return 0; +} + +/* RS4 : L'entrée et les sorties du labyrinthe doivent se situer sur la périphérie + * du labyrinthe */ +int RS4(Point E, Point* S, int nb_S, Point size){ + int i; + Point tmp; + + if (S == NULL){ + printf("RS4 : La liste des sorties est vide.\n"); + exit(1); + } + + if (E.c != 0 && E.l != 0 && E.c != size.c && E.l != size.l){ + return 0; + } + + else { + for (i=0 ; i<nb_S ; i++){ + tmp = S[i]; + if (tmp.c != 0 && tmp.l != 0 && tmp.c != size.c && tmp.l != size.l){ + return 0; + } + } + } + return 1; + } + + +/*int main(){ + Point size = new_point(5,6); + + Point entree1 = new_point(0,0); + Point entree2 = new_point(5,6); + Point entree3 = new_point(5,0); + Point entree4 = new_point(0,5); + + + Point* listeS = NULL; + listeS = calloc(1,sizeof(Point)); + listeS[0] = new_point(0,0); + printf("listeS[0] : (%d,%d)\n",listeS[0].c, listeS[0].l); + + printf("Test entree1 : %d\n", RS4(entree1,listeS,1,size)); + printf("Test entree2 : %d\n", RS4(entree2,listeS,1,size)); + printf("Test entree3 : %d\n", RS4(entree3,listeS,1,size)); + printf("Test entree4 : %d\n", RS4(entree4,listeS,1,size)); + + + return 0; +}*/ + + + +int main () { + char*** matrice = create_matrice(5,6); + + Point p1 = new_point(4,2); + printf("Point p1 (%d,%d)\n",p1.c,p1.l); printf("\nAppel de la fonction change_val_matrice(p1,ABC)\n"); change_val_matrice(p1,"ABC",matrice); @@ -165,7 +262,7 @@ void create_modif_var(char* nom, int val) { change_val_matrice(p1, "DEF", matrice); printf("Point p1 :%s\n", lecture(p1,matrice)); - printf("\nTaille de la matrice : (%d,%d)\n",size.x-1,size.y-1); + printf("\nTaille de la matrice : (%d,%d)\n",size.c,size.l); printf("Matrice correspondante :\n"); affichmat(matrice); @@ -181,4 +278,4 @@ void create_modif_var(char* nom, int val) { printf("Deuxième valeur : %d\n",listevars.val[1]); return 0; -}*/ +} diff --git a/Labgen/labgen.h b/Labgen/labgen.h index 5aeb11e8c231196a756982fcf97aef8c28398ad1..c943c5282df173286d2597e5c0ef6546d72d665f 100644 --- a/Labgen/labgen.h +++ b/Labgen/labgen.h @@ -4,9 +4,9 @@ #define TAILLE 255 typedef struct { -int x; -int y; -} point; +int c; +int l; +} Point; typedef struct { char* ident[TAILLE]; @@ -14,11 +14,11 @@ int val[TAILLE]; int last; } variables; -point new_point(int ,int); +Point new_point(int ,int); char*** create_matrice(int,int); -char* lecture(point,char***); -void change_val_matrice(point,char*, char***); +char* lecture(Point,char***); +void change_val_matrice(Point,char*, char***); void affichmat(char***); void init_listevars();