Skip to content
Extraits de code Groupes Projets
Valider f8f66db8 rédigé par Hélène TRAN's avatar Hélène TRAN
Parcourir les fichiers

Grand nettoyage et explications des fonctions utiles dans le .h

parent ead19b56
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -99,7 +99,6 @@ void change_val_matrice(Point p, char * msg, char*** matrice) ...@@ -99,7 +99,6 @@ void change_val_matrice(Point p, char * msg, char*** matrice)
} }
void ligne(Point sizeLAB){ void ligne(Point sizeLAB){
int j; int j;
printf(" +"); printf(" +");
...@@ -108,6 +107,7 @@ void ligne(Point sizeLAB){ ...@@ -108,6 +107,7 @@ void ligne(Point sizeLAB){
printf("\n"); printf("\n");
} }
void affichmat(char*** matrice, Point sizeLAB) { void affichmat(char*** matrice, Point sizeLAB) {
int i,j; int i,j;
char* tmp; char* tmp;
...@@ -173,146 +173,6 @@ Point** add_tab(Point pt, Point** tab, int taille){ ...@@ -173,146 +173,6 @@ Point** add_tab(Point pt, Point** tab, int taille){
} }
void check_obligatoire(variables listCount){
if (find_var("IN",listCount) == -1){
fprintf(stderr,"Erreur : IN n'existe pas.");
exit(1);
}
if (find_var("OUT",listCount) == -1){
fprintf(stderr,"Erreur : OUT n'existe pas.\n");
exit(1);
}
if (find_var("SIZE",listCount) == -1){
fprintf(stderr,"Erreur : SIZE n'existe pas.\n");
exit(1);
}
}
/*int check_show(char* id, variables listevars){
int index = find_var(id,listevars);
if (index == -1){
fprintf(stderr,"Erreur : %s n'existe pas.\n",id);
exit(1);
}
return index;
}*/
/* La fonction show permet l'affichage de la matrice du labyrinthe
* listLAB contient toutes les informations sur le labyrinthe
* On suppose qu'on a dans listLAB:
* - SIZEc : la colonne de SIZE
* - SIZEl : la ligne de SIZE
* - INc : la colonne de IN
* - INl : la ligne de IN
* - OUTc : la colonne de OUT
* - OUTl : la ligne de OUT */
/* Conventions finales :
* - Point size
* - Point in
* - Point** listOUT (tableau de pointeurs sur un Point OUT)
* - Point** listWALL (tableau de pointeurs sur un Point WALL)
* - Point** listTDV (tableau de pointeurs sur un Point TDV)
* - varpoint*** listPM (tableau de pointeurs sur un pointeur pointant sur un listevars)
* - */
void show(Point size, Point in, Point** listOUT, Point** listWALL,
Point** listTDV, varpoint** listPM, variables listCOUNT){
char*** mat;
int i,n;
int index;
Point pt;
varpoint var;
char s[100];
/* Vérifie qu'on a des informations sur la taille, l'entrée et au moins
* une sortie du labyrinthe */
check_obligatoire(listCOUNT);
mat = create_matrice(size.c,size.l);
/* Ajout de l'entrée*/
change_val_matrice(in,"E ",mat);
/* Ajout des sorties */
n=value_var("OUT",listCOUNT);
for (i=0 ; i<n ; i++){
pt = *(listOUT[i]);
change_val_matrice(pt,"O ",mat);
}
/* Ajout des murs */
n=value_var("WALL",listCOUNT);
for (i=0 ; i<n ; i++){
pt = *(listWALL[i]);
change_val_matrice(pt,"* ",mat);
}
/* Ajout des trous de vers */
n=value_var("TDV",listCOUNT);
for (i=0 ; i<n ; i=i+2){
pt = *(listTDV[i]);
sprintf(s,"%d",i);
char chaine1[100] = "W";
char chaine2[100] = "w";
strcat(chaine1,s);
strcat(chaine2,s);
change_val_matrice(pt,chaine1,mat);
pt = *(listTDV[i+1]);
change_val_matrice(pt,chaine2,mat);
}
/* Ajout des portes magiques */
n = value_var("PM",listCOUNT);
for (i=0 ; i<n ; i++){
var = *(listPM[i]);
index=find_varpoint("DEP",var);
if (index==-1){
fprintf(stderr,"Erreur : pas de point de départ de porte magique.\n");
exit(1);
}
pt = value_varpoint("DEP",var);
change_val_matrice(pt,"A ",mat);
for (i=0 ; i<8 ; i++){
if ((index = find_varpoint(DIR[i],var)) != -1){
pt = value_varpoint(DIR[i],var);
sprintf(s,"%d",i);
char chaine1[100] = "a";
strcat(chaine1,s);
change_val_matrice(pt,chaine1,mat);
}
}
/*if ((index = find_varpoint("N",var)) != -1){
pt = value_varpoint("N",var);
change_val_matrice(pt,"AN",mat);
}
if ((index = find_varpoint("E",var)) != -1){
pt = value_varpoint("E",var);
change_val_matrice(pt,"AE",mat);
}
if ((index = find_varpoint("W",var)) != -1){
pt = value_varpoint("W",var);
change_val_matrice(pt,"AW",mat);
}
if ((index = find_varpoint("S",var)) != -1){
pt = value_varpoint("S",var);
change_val_matrice(pt,"AS",mat);
}*/
}
affichmat(mat,size);
}
/******************************************************************************/ /******************************************************************************/
/* Fonctions de base de listevars */ /* Fonctions de base de listevars */
...@@ -389,8 +249,8 @@ variables create_modif_var(char* nom, int val, variables listevars) { ...@@ -389,8 +249,8 @@ variables create_modif_var(char* nom, int val, variables listevars) {
* - si l'identifiant existe dans listevars, il incrémente la valeur existante * - si l'identifiant existe dans listevars, il incrémente la valeur existante
* - sinon, il crée l'identifiant et l'initialise à 1 * - sinon, il crée l'identifiant et l'initialise à 1
* Utile pour listCOUNT */ * Utile pour listCOUNT */
variables increment_var(char* nom,variables listevars){ variables increment_var(char* var,variables listevars){
int index = find_var(nom,listevars); int index = find_var(var,listevars);
if (index != -1) if (index != -1)
listevars.val[index] ++; listevars.val[index] ++;
...@@ -401,10 +261,10 @@ variables increment_var(char* nom,variables listevars){ ...@@ -401,10 +261,10 @@ variables increment_var(char* nom,variables listevars){
exit(1); exit(1);
} }
else{ else{
listevars.ident[listevars.last] = malloc(strlen(nom)*sizeof(char)); listevars.ident[listevars.last] = malloc(strlen(var)*sizeof(char));
} }
strcpy(listevars.ident[listevars.last],nom); strcpy(listevars.ident[listevars.last],var);
listevars.val[listevars.last] = 1; listevars.val[listevars.last] = 1;
listevars.last++; listevars.last++;
} }
...@@ -482,6 +342,99 @@ varpoint create_modif_varpoint(char* nom, Point val, varpoint list) { ...@@ -482,6 +342,99 @@ varpoint create_modif_varpoint(char* nom, Point val, varpoint list) {
} }
void check_obligatoire(variables listCount){
if (find_var("IN",listCount) == -1){
fprintf(stderr,"Erreur : IN n'existe pas.");
exit(1);
}
if (find_var("OUT",listCount) == -1){
fprintf(stderr,"Erreur : OUT n'existe pas.\n");
exit(1);
}
if (find_var("SIZE",listCount) == -1){
fprintf(stderr,"Erreur : SIZE n'existe pas.\n");
exit(1);
}
}
void show(Point size, Point in, Point** listOUT, Point** listWALL,
Point** listTDV, varpoint** listPM, variables listCOUNT){
char*** mat;
int i,n;
int index;
Point pt;
varpoint var;
char s[100];
/* Vérifie qu'on a des informations sur la taille, l'entrée et au moins
* une sortie du labyrinthe */
check_obligatoire(listCOUNT);
mat = create_matrice(size.c,size.l);
/* Ajout de l'entrée*/
change_val_matrice(in,"E ",mat);
/* Ajout des sorties */
n=value_var("OUT",listCOUNT);
for (i=0 ; i<n ; i++){
pt = *(listOUT[i]);
change_val_matrice(pt,"O ",mat);
}
/* Ajout des murs */
n=value_var("WALL",listCOUNT);
for (i=0 ; i<n ; i++){
pt = *(listWALL[i]);
change_val_matrice(pt,"* ",mat);
}
/* Ajout des trous de vers */
n=value_var("TDV",listCOUNT);
for (i=0 ; i<n ; i=i+2){
pt = *(listTDV[i]);
sprintf(s,"%d",i);
char chaine1[100] = "W";
char chaine2[100] = "w";
strcat(chaine1,s);
strcat(chaine2,s);
change_val_matrice(pt,chaine1,mat);
pt = *(listTDV[i+1]);
change_val_matrice(pt,chaine2,mat);
}
/* Ajout des portes magiques */
n = value_var("PM",listCOUNT);
for (i=0 ; i<n ; i++){
var = *(listPM[i]);
index=find_varpoint("DEP",var);
if (index==-1){
fprintf(stderr,"Erreur : pas de point de départ de porte magique.\n");
exit(1);
}
pt = value_varpoint("DEP",var);
change_val_matrice(pt,"A ",mat);
for (i=0 ; i<8 ; i++){
if ((index = find_varpoint(DIR[i],var)) != -1){
pt = value_varpoint(DIR[i],var);
sprintf(s,"%d",i);
char chaine1[100] = "a";
strcat(chaine1,s);
change_val_matrice(pt,chaine1,mat);
}
}
}
affichmat(mat,size);
}
/* Test des fonctions de base de la matrice et de listevars */ /* Test des fonctions de base de la matrice et de listevars */
int main() { int main() {
/* Tester varpoint */ /* Tester varpoint */
......
...@@ -22,30 +22,115 @@ Point* val[TAILLE]; ...@@ -22,30 +22,115 @@ Point* val[TAILLE];
int last; int last;
} varpoint; } varpoint;
/******************************************************************************/
/* Fonctions de création de structure de points */
/******************************************************************************/
/* [new_point(c,l)] crée un nouveau point de coordonnées (c,l) */
Point new_point(int ,int); Point new_point(int ,int);
/* [new_point_ptr(c,l)] crée un nouveau pointeur de point de coordonnées (c,l) */
Point* new_point_ptr(int, int); Point* new_point_ptr(int, int);
/******************************************************************************/
/* Fonctions de base de matrices */
/******************************************************************************/
/* [create_matrice(c,l)] crée une matrice à c colonnes et l lignes */
char*** create_matrice(int,int); char*** create_matrice(int,int);
/* [lecture(p,matrice)] renvoie la valeur de la matrice de coordonnées p */
char* lecture(Point,char***); char* lecture(Point,char***);
/* [change_val_matrice(p,msg,matrice)] hange la valeur de la matrice de
* coordonnées p par la valeur msg */
void change_val_matrice(Point,char*, char***); void change_val_matrice(Point,char*, char***);
/* [affichmat(mat,sizeLAB)] affiche sur la sortie standard la matrice
* de taille sizeLAB */
void affichmat(char***,Point); void affichmat(char***,Point);
/******************************************************************************/
/* Fonctions de base d'un tableau dynamique de pointeurs */
/******************************************************************************/
/* [init_tab(size)] initialise un tableau de pointeurs à une dimension */
Point** init_tab(Point size);
/* [add_tab pt(tab,taille)] ajoute un point à un tableau de pointeurs */
Point** add_tab(Point pt, Point** tab, int taille);
/******************************************************************************/
/* Fonctions de base de la structure variables */
/******************************************************************************/
/* [init_listevars()] initialise une structure de type variables */
variables init_listevars(); variables init_listevars();
/* [find_var(var,listevars)] vérifie si l'identifiant var est dans listevars */
int find_var(char*,variables); int find_var(char*,variables);
/* [value_var(var,listevars)] renvoie la valeur de l'identifiant var
* dans listevars */
int value_var(char*,variables); int value_var(char*,variables);
/* [create_modif_var(nom,val,listevars)] modifie la valeur associée à l'identifiant :
* - Si "nom" fait partie de la liste des variables, alors la variable est
* directement modifiée
* - Sinon rajoute le nom de la variable et sa valeur dans listevars
si la taille de listevars le permet */
variables create_modif_var(char*,int,variables); variables create_modif_var(char*,int,variables);
/* [increment_var(var,listevars)] incrémente la valeur de l'identifiant :
* - si l'identifiant var existe dans listevars, il incrémente la valeur existante
* - sinon, il crée l'identifiant et l'initialise à 1
* Utile pour listCOUNT */
variables increment_var(char*,variables); variables increment_var(char*,variables);
/******************************************************************************/
/* Fonctions de base de la structure varpoint */
/******************************************************************************/
/* [init_listevarpoint()] initialise une structure de type varpoint */
varpoint init_listevarpoint(); varpoint init_listevarpoint();
int find_varpoint(char* var,varpoint list); /* [find_varpoint(var,list)] vérifie si l'identifiant var est dans list */
Point value_varpoint(char* var,varpoint list); int find_varpoint(char*,varpoint);
varpoint create_modif_varpoint(char* nom, Point val, varpoint list); /* [value_varpoint(var,list)] renvoie la valeur de l'identifiant var dans list */
Point value_varpoint(char*,varpoint);
/* [create_modif_varpoint(nom,val,list)] modifie la valeur val associée à
* l'identifiant :
* - Si "nom" fait partie de la liste des variables, alors la variable est
* directement modifiée
* - Sinon rajoute le nom de la variable et sa valeur dans list
si la taille de list le permet */
varpoint create_modif_varpoint(char*,Point,varpoint);
Point** init_tab(Point size);
int equals_pt(Point pt1, Point pt2);
Point** add_tab(Point pt, Point** tab, int taille);
void show(Point size, Point in, Point** listOUT, Point** listWALL, Point** listTDV, varpoint** listPM, variables listCOUNT); /******************************************************************************/
/* Fonctions utiles au fichier labgen.y */
/******************************************************************************/
/* Conventions finales sur la récupération d'informations du labyrinthe :
* - Point size : taille du labyrinthe
* - Point in : unique point d'entrée IN du labyrinthe
* - Point** listOUT : tableau de pointeurs des points de sortie OUT
* - Point** listWALL : tableau de pointeurs des points représentant les murs WALL
* - Point** listTDV : tableau de pointeurs des points représentant
les trous de vers TDV
* - varpoint** listPM : tableau de pointeurs sur un varpoint
* -> pour listPM, on a n éléments de tableaux
* -> pour chaque élément, on a un pointeur pointant vers
* une structure de type varpoint
* -> Cette structure varpoint a pour :
* - identifiant : la direction (N,W,S,NE,...)
* - valeur : un pointeur sur le point correspondant
* à la direction indiquée
* -> Le point de départ est spécifié dans la structure
* varpoint et a pour identifiant "DEP"
* - variables listCOUNT : compte le nombre de points associés à chaque
* identifiant SIZE, IN, OUT, WALL, TDV, PM
* Par exemple : 1 point pour SIZE et pour IN
* 3 points pour OUT */
/* [show(size, in, listOUT, listWALL, listTDV, listPM, listCOUNT)] fait afficher
* la matrice correspondant aux informations données sur le labyrinthe */
void show(Point, Point, Point**, Point**, Point**, varpoint**, variables);
int RS1(Point); int RS1(Point);
int RS2_count(int); int RS2_count(int);
int RS3_count(int); int RS3_count(int);
......
#ifndef _LABGEN_RS_H
#define _LABGEN_RS_H
int RS1(Point size);
int RS2_count(int countE);
int RS3_count(int countS);
/* A compléter et régler le problème d'inclusion */
#endif
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter