diff --git a/Makefile b/Makefile index 7a9e545eda4eeb67a958c435e5605f2f708617de..dbf2c0c8b14b114b37ff0d6bdc2251abdcaaf9bb 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ $(BINPATH)lavie: $(addprefix $(OBJPATH), main.o) $(LIBPATH)libjeu.a | $(BINPATH) gcc $(LDFLAGS) -o $@ $< $(LDLIBS) @echo Compilation texte est fait -$(LIBPATH)libjeu.a: $(addprefix $(OBJPATH), graphique_module.o grille.o io.o jeu.o) |$(LIBPATH) +$(LIBPATH)libjeu.a: $(addprefix $(OBJPATH), graphique_module.o grille.o io.o jeu.o teste_osci.o) |$(LIBPATH) ar -crv $@ $^ $(OBJPATH)main.o: main.c grille.h io.h jeu.h @@ -72,7 +72,7 @@ clean: dist: tar -czf $(ARCHIVE).tar.gz \ - src/*.c include/*.h bin/ Makefile Doc test/*.sh grilles/*.txt .gitlab-ci.yml + src/*.c include/*.h bin/ Makefile test/*.sh grilles/*.txt .gitlab-ci.yml doc: $(DOCGEN) diff --git a/TANG_Huayi.GrTP3.tar.gz b/TANG_Huayi.GrTP3.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..b61cbf643f4a028b543b1e3fcadc367cbf5736ba Binary files /dev/null and b/TANG_Huayi.GrTP3.tar.gz differ diff --git a/bin/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin b/bin/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin new file mode 100644 index 0000000000000000000000000000000000000000..bbab965b72f7b869c3c58a1177636a3d046736cd Binary files /dev/null and b/bin/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin differ diff --git a/bin/visio b/bin/visio index b28255498cc3a6c09a3e219861caa1dfe2636cca..5d76a2bf5ec438582d690bf161090a7e3da9cd69 100755 Binary files a/bin/visio and b/bin/visio differ diff --git a/include/.vscode/ipch/16c374b1fa0c4966/mmap_address.bin b/include/.vscode/ipch/16c374b1fa0c4966/mmap_address.bin new file mode 100644 index 0000000000000000000000000000000000000000..61aeb17489126c025a2a1e409ce7151e66e62832 Binary files /dev/null and b/include/.vscode/ipch/16c374b1fa0c4966/mmap_address.bin differ diff --git a/include/.vscode/ipch/7473f96d99a80d6d/graphique_module.ipch b/include/.vscode/ipch/7473f96d99a80d6d/graphique_module.ipch new file mode 100644 index 0000000000000000000000000000000000000000..aec5e6bd1ed9d2cee70800da05d3b5b65a421efa Binary files /dev/null and b/include/.vscode/ipch/7473f96d99a80d6d/graphique_module.ipch differ diff --git a/include/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin b/include/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin new file mode 100644 index 0000000000000000000000000000000000000000..b7be0254bda190b2df0ca8b159bd8f44ebca15b2 Binary files /dev/null and b/include/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin differ diff --git a/include/graphique_module.h b/include/graphique_module.h index 5632be31b325a47eef6703744b5559bae093c968..73b989ef248f3fd351618e81e9cd6d56ec475528 100644 --- a/include/graphique_module.h +++ b/include/graphique_module.h @@ -12,6 +12,7 @@ #include <cairo.h> #include <cairo-xlib.h> #include <X11/Xlib.h> +#include "teste_osci.h" #include "jeu.h" diff --git a/include/teste_osci.h b/include/teste_osci.h new file mode 100644 index 0000000000000000000000000000000000000000..57991cab7a0484584d6b5098724a5c6d9df22f1c --- /dev/null +++ b/include/teste_osci.h @@ -0,0 +1,38 @@ +#ifndef _TESTE_OSCI_H +#define _TESTE_OSCI_H + +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> +#include <cairo.h> +#include <cairo-xlib.h> +#include <X11/Xlib.h> +#include "grille.h" +#include "jeu.h" +#include "teste_osci.h" +#include "graphique_module.h" + +typedef struct liste_grille{ + int age; + grille* element; + struct liste_grille* suivant; +} liste_grille; + + + +liste_grille* nouvelle_liste(); + +void inserer_liste(grille* g, liste_grille* l); + +bool grille_identique(grille * g_courant, grille * g_element); + +bool grille_vide(const grille *const g_courant); + +void teste_oscii(grille* g,cairo_surface_t* surface,int (*compte_voisins_vivants)(int,int,grille)); + + + +#endif //_TESTE_OSCI_H diff --git a/lib/libjeu.a b/lib/libjeu.a index a56436f452f219770ba0ec4a26cfc2bc25e1d3ad..d74672d5e59333e7b374a730bd4b4b78bac9e1fa 100644 Binary files a/lib/libjeu.a and b/lib/libjeu.a differ diff --git a/obj/graphique_module.o b/obj/graphique_module.o index 01bf29b8d9a771bd9f1c828da9c249d1014d455a..40bef298341316d8a5991601f73931c9c9f728f8 100644 Binary files a/obj/graphique_module.o and b/obj/graphique_module.o differ diff --git a/obj/teste_osci.o b/obj/teste_osci.o new file mode 100644 index 0000000000000000000000000000000000000000..8c41bc1fd916b49768107876f4a5e54312bcaa59 Binary files /dev/null and b/obj/teste_osci.o differ diff --git a/src/.vscode/ipch/16c374b1fa0c4966/mmap_address.bin b/src/.vscode/ipch/16c374b1fa0c4966/mmap_address.bin new file mode 100644 index 0000000000000000000000000000000000000000..567cabe0262994539592336fdb60bc04d6811574 Binary files /dev/null and b/src/.vscode/ipch/16c374b1fa0c4966/mmap_address.bin differ diff --git a/src/.vscode/ipch/43e82087c78d3ee9/mmap_address.bin b/src/.vscode/ipch/43e82087c78d3ee9/mmap_address.bin new file mode 100644 index 0000000000000000000000000000000000000000..991429ea5412f2ebd0a51691ef3e4d7cb4a55ad7 Binary files /dev/null and b/src/.vscode/ipch/43e82087c78d3ee9/mmap_address.bin differ diff --git a/src/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin b/src/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin new file mode 100644 index 0000000000000000000000000000000000000000..f458bfc26a5a6dbad2031187c8cb7db82a8d07fb Binary files /dev/null and b/src/.vscode/ipch/7473f96d99a80d6d/mmap_address.bin differ diff --git a/src/graphique_module.c b/src/graphique_module.c index 196ae09f8cc1a3a5ad3f99c1c44224049d406c41..45f32c36c6edcd78bd25f5da7d7d0a9d5f711d60 100644 --- a/src/graphique_module.c +++ b/src/graphique_module.c @@ -7,6 +7,7 @@ #include "grille.h" #include "graphique_module.h" #include <string.h> +#include "teste_osci.h" void print_life(cairo_t *cr, char* str,double pos_xt,double pos_yt, double t_size){ cairo_set_source_rgb(cr, 1, 0.74901, 0); @@ -192,9 +193,14 @@ void corp_jeu(grille *g, grille *gc, cairo_surface_t *cs, XEvent e, Display *dpy print_string(cs,cylique,150,20,20); print_string(cs,turn, 20.0, 20.0, 20.0); } + else if (e.type==KeyPress && e.xkey.keycode==32){ //keycode for key button "o" + teste_oscii(g,cs,compte_voisins_vivants); + + + } else if (e.type==ButtonPress && e.xbutton.button==3) break; } -} +} \ No newline at end of file diff --git a/src/teste_osci.c b/src/teste_osci.c new file mode 100644 index 0000000000000000000000000000000000000000..0006721d90d8314378a22de008a868453dcc65a0 --- /dev/null +++ b/src/teste_osci.c @@ -0,0 +1,145 @@ +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> +#include <cairo.h> +#include <cairo-xlib.h> +#include <X11/Xlib.h> +#include "grille.h" +#include "jeu.h" +#include "teste_osci.h" +#include "graphique_module.h" + + +liste_grille* nouvelle_liste(grille* g){ + liste_grille* liste=(liste_grille*)malloc(sizeof(liste_grille*)); + grille* gt_locale=(grille*) malloc (sizeof(grille*)); + alloue_grille(g->nbl,g->nbc,gt_locale); + copie_grille(g,gt_locale); + liste->age=0; + liste->element=gt_locale; + liste->suivant=NULL; + return liste; +} + +void inserer_liste(grille* g, liste_grille* l){ + + liste_grille* maillon= (liste_grille *) malloc (sizeof(liste_grille*)); + if(!maillon) exit(-1); + + + grille* gt_locale=(grille*) malloc (sizeof(grille*)); + alloue_grille(g->nbl,g->nbc,gt_locale); + copie_grille(g,gt_locale); + + maillon->element=gt_locale; + maillon->suivant=NULL; + liste_grille* courant=l; + while (courant->suivant){ + courant=courant->suivant; + } + maillon->age=courant->age+1; + courant->suivant=maillon; +} + + +void liberer_liste(liste_grille* l){ + liste_grille* courant=l; + while(courant->suivant){ + l=courant->suivant; + if(courant->element) + libere_grille(courant->element); + free(courant); + courant=l; + } + if(courant->element) + libere_grille(courant->element); + free(courant); +} + + +bool grille_identique(grille * g_courant, grille * g_element) { + + for (int i = 0; i < g_courant->nbl; ++i) + for (int j = 0; j < g_courant->nbc; ++j) + { + + if((est_vivante(i,j,*g_courant)&&!est_vivante(i,j,*g_element))||(!est_vivante(i,j,*g_courant)&&est_vivante(i,j,*g_element))) + return false; + + } + + + return true; +} + + +bool grille_vide(const grille *const g_courant) { + + for (int i = 0; i < g_courant->nbl; ++i) + for (int j = 0; j < g_courant->nbc; ++j) + if(est_vivante(i,j,*g_courant)) return false; + return true; +} + +void teste_oscii(grille* g,cairo_surface_t* surface,int (*compte_voisins_vivants)(int,int,grille)){ + + bool oscii=false; + grille* g_locale=(grille*) malloc (sizeof(grille*)); + grille* gc_locale=(grille*) malloc (sizeof(grille*)); + alloue_grille(g->nbl,g->nbc,g_locale); + alloue_grille(g->nbl,g->nbc,gc_locale); + copie_grille(g,g_locale); + liste_grille* l=nouvelle_liste(g); + +while(!oscii){ + evolue(g_locale,gc_locale,compte_voisins_vivants); + if(grille_vide(g_locale)){ + char str[50]="Tous les cellules sont fortes à la fin!"; + print_string(surface,str,30,SIZEY-30,15); + oscii=true; + break; + } + + liste_grille* courant=l; + while(courant->suivant){ + if(grille_identique(g_locale,courant->element)){ + + if(courant->suivant){ + int start=courant->age; + int period=0; + while(courant->suivant){ + period++; + courant=courant->suivant; + } + char str[50]="Cette colonie est oscilent depuis étape: "; + char int_str[5]="\0"; + sprintf(int_str,"%d",start); + strcat(str,int_str); + print_string(surface,str,20,SIZEY-30,15); + + char pstr[50]="La période de cette OS est : "; + char period_str[5]="\0"; + sprintf(period_str,"%d",period); + strcat(pstr,period_str); + print_string(surface,pstr,400,SIZEY-30,15); + oscii=true; + break; + } + } + else{ + courant=courant->suivant; + } + } + + inserer_liste(g_locale,l); +} + + libere_grille(g_locale); + libere_grille(gc_locale); + free(g_locale); + free(gc_locale); + liberer_liste(l); +} \ No newline at end of file