diff --git a/Labgen/labgen.c b/Labgen/labgen.c index 1f88ae02fb5899fff06cdbe15b1e4c06456913a7..76dd5b43c3055e5f43041c7a3e5b89f83fe282a5 100644 --- a/Labgen/labgen.c +++ b/Labgen/labgen.c @@ -1,7 +1,7 @@ #include "labgen.h" -#include<stdio.h> -#include<stdlib.h> -#include<string.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> char DIR[8][3] = {"N","NE","E","SE","S","SW","W","NW"}; Point size; @@ -99,7 +99,6 @@ void change_val_matrice(Point p, char * msg, char*** matrice) } - void ligne(Point sizeLAB){ int j; printf(" +"); @@ -108,6 +107,7 @@ void ligne(Point sizeLAB){ printf("\n"); } + void affichmat(char*** matrice, Point sizeLAB) { int i,j; char* tmp; @@ -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 */ @@ -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 * - sinon, il crée l'identifiant et l'initialise à 1 * Utile pour listCOUNT */ -variables increment_var(char* nom,variables listevars){ - int index = find_var(nom,listevars); +variables increment_var(char* var,variables listevars){ + int index = find_var(var,listevars); if (index != -1) listevars.val[index] ++; @@ -401,10 +261,10 @@ variables increment_var(char* nom,variables listevars){ exit(1); } 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.last++; } @@ -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 */ int main() { /* Tester varpoint */ diff --git a/Labgen/labgen.h b/Labgen/labgen.h index 68309da06050ebc510c66627522513c0ae4a8a02..5faa86a414e10bfb6d954da29da777649f2d9c23 100644 --- a/Labgen/labgen.h +++ b/Labgen/labgen.h @@ -22,30 +22,115 @@ Point* val[TAILLE]; int last; } 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); +/* [new_point_ptr(c,l)] crée un nouveau pointeur de point de coordonnées (c,l) */ 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); +/* [lecture(p,matrice)] renvoie la valeur de la matrice de coordonnées p */ 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***); +/* [affichmat(mat,sizeLAB)] affiche sur la sortie standard la matrice + * de taille sizeLAB */ 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(); +/* [find_var(var,listevars)] vérifie si l'identifiant var est dans listevars */ int find_var(char*,variables); +/* [value_var(var,listevars)] renvoie la valeur de l'identifiant var + * dans listevars */ 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); +/* [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); + +/******************************************************************************/ +/* Fonctions de base de la structure varpoint */ +/******************************************************************************/ + +/* [init_listevarpoint()] initialise une structure de type varpoint */ varpoint init_listevarpoint(); -int find_varpoint(char* var,varpoint list); -Point value_varpoint(char* var,varpoint list); -varpoint create_modif_varpoint(char* nom, Point val, varpoint list); +/* [find_varpoint(var,list)] vérifie si l'identifiant var est dans list */ +int find_varpoint(char*,varpoint); +/* [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 RS2_count(int); int RS3_count(int); diff --git a/Labgen/labgen_RS.h b/Labgen/labgen_RS.h new file mode 100644 index 0000000000000000000000000000000000000000..02426da282dda0306e429faa4cad03882d943b44 --- /dev/null +++ b/Labgen/labgen_RS.h @@ -0,0 +1,11 @@ +#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