Commit cd8a8cf6 authored by Valentin MEUNIER's avatar Valentin MEUNIER
Browse files

enfin

parent de4059ec
...@@ -35,5 +35,4 @@ void partition_connexe(partition_t *,graph_t *,int); ...@@ -35,5 +35,4 @@ void partition_connexe(partition_t *,graph_t *,int);
void affiche_graph2(graph_t *,partition_t *, int, int,int); void affiche_graph2(graph_t *,partition_t *, int, int,int);
int main();
#endif #endif
...@@ -2,27 +2,46 @@ ...@@ -2,27 +2,46 @@
int ** tableau_ligne(graph_t * graph,int nb_aretes) int ** tableau_ligne(graph_t * graph,int nb_aretes)
{ {
int** tab=malloc(N*sizeof(int*)); int** tab=malloc(P*sizeof(int*));
for (int i=0; i<N; i++) for (int i=0; i<P; i++)
tab[i]=malloc(P*sizeof(int)); tab[i]=malloc(N*sizeof(int));
for (int i=0; i<P; i++)
for (int j=0; j<N; j++)
tab[i][j]=0;
int diff; int diff;
int x; int x;
int y; int y;
for (int i=0; i<nb_aretes; i++) for (int i=0; i<nb_aretes; i++)
{ {
diff=graph->liste[i].un - graph->liste[i].deux; diff=abs(graph->liste[i].un - graph->liste[i].deux);
x=graph->liste[i].un%N; x=graph->liste[i].un%P;
y=graph->liste[i].un%P; y=graph->liste[i].un/P;
if (x==0) // printf("sommet1: %d sommet2: %d x :%d y :%d diff :%d\n",graph->liste[i].un,graph->liste[i].deux,x,y,diff);
tab[x][y]+=8;
if (y==0)
tab[x][y]+=1;
if (diff==1) if (diff==1)
tab[x][y]+=4; tab[x][y]+=4;
else else // ne marche pas c'est incomprehensibleif (diff==P)
tab[x][y]+=2; tab[x][y]+=2;
} }
return tab; /*
for (int i=0; i<N; i++)
{
tab[i][0]-=8;
tab[i][P-1]-=4;
}
for(int j=0; j<P; j++)
{
tab[0][j]-=1;
tab[N-1][j]-=2;
}*/
/* for (int i=0; i<N; i++)
{
for (int j=0; j<P; j++)
printf("%d ", tab[j][i]);
printf("\n");
}*/
return tab;
} }
graph_t * kruskal(graph_t * graph,int noeuds, int nb_aretes,int * cours) graph_t * kruskal(graph_t * graph,int noeuds, int nb_aretes,int * cours)
...@@ -65,32 +84,27 @@ graph_t * Fisher(graph_t * graph, int nb_aretes) ...@@ -65,32 +84,27 @@ graph_t * Fisher(graph_t * graph, int nb_aretes)
return graph; return graph;
} }
int generation(graph_t * graph, int n, int p) void generation(graph_t * graph)
{ {
int nb_aretes=0; int c=0;
int rand1; for (int i=0; i<N*P; i++)
int rand2;
for (int i=0; i<n*p; i++)
{ {
rand1=(rand()%8);
rand2=(rand()%8); if ((i+1)%P)
printf("%d %d\n",rand1,rand2);
if (rand1 && (i+1)%n)
{ {
graph->liste[nb_aretes].un=i; graph->liste[c].un=i;
graph->liste[nb_aretes].deux=i+1; graph->liste[c].deux=i+1;
graph->liste[nb_aretes].valuation=1; graph->liste[c].valuation=1;
nb_aretes++; c++;
} }
if (rand2 && i<(n-1)*p) if (i/P<N-1)
{ {
graph->liste[nb_aretes].un=i; graph->liste[c].un=i;
graph->liste[nb_aretes].deux=i+n; graph->liste[c].deux=i+P;
graph->liste[nb_aretes].valuation=1; graph->liste[c].valuation=1;
nb_aretes++; c++;
} }
} }
return nb_aretes;
} }
/* /*
int main() int main()
......
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
#include "tas.h" #include "tas.h"
#include "graph_aretes_tab.h" #include "graph_aretes_tab.h"
#define N 4 #define N 30
#define P 5 #define P 52
graph_t * kruskal(graph_t * graph,int noeuds, int nb_aretes,int * cours); graph_t * kruskal(graph_t * graph,int noeuds, int nb_aretes,int * cours);
graph_t * Fisher(graph_t * graph, int nb_aretes); graph_t * Fisher(graph_t * graph, int nb_aretes);
int generation(graph_t * graph, int n, int p); void generation(graph_t * graph);
int ** tableau_ligne(graph_t *,int ); int ** tableau_ligne(graph_t *,int );
......
...@@ -27,40 +27,40 @@ void end_sdl(char ok,char const* msg,SDL_Window* window, SDL_Renderer* renderer) ...@@ -27,40 +27,40 @@ void end_sdl(char ok,char const* msg,SDL_Window* window, SDL_Renderer* renderer)
void afficherEcranIntelligemment(SDL_Renderer *renderer,int **tab,int taille_cell) void afficherEcranIntelligemment(SDL_Renderer *renderer,int **tab,int taille_cell)
{ {
int i1,j1,x,noeud=0; int x=0;
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer,0,0,0,0); SDL_SetRenderDrawColor(renderer,255,0,0,0);
SDL_RenderDrawLine(renderer,0,0,P*taille_cell,0); //mur au nord
SDL_RenderDrawLine(renderer,0,N*taille_cell,P*taille_cell,(N)*taille_cell); //mur au sud
SDL_RenderDrawLine(renderer,0,0,0,(N)*taille_cell); //mur à l'ouest
SDL_RenderDrawLine(renderer,(P)*taille_cell,0,(P)*taille_cell,(N)*taille_cell); //mur à l'est
for (int i=0;i<N;i++) SDL_SetRenderDrawColor(renderer,0,0,0,0);
for (int i=0;i<P;i++)
{ {
for (int j=0;j<P;j++) for (int j=0;j<N;j++)
{ {
x=tab[i][j]; x=tab[i][j];
i1=(noeud%P)+1;
j1=(noeud/P)+1; if ((x!=2) && (x!=6))
printf("%d %d \n",noeud,x); SDL_RenderDrawLine(renderer,i*taille_cell,(j+1)*taille_cell,(i+1)*taille_cell,(j+1)*taille_cell); //mur au sud
if ((x!=4) && (x!=6))
if (x%2!=1) SDL_RenderDrawLine(renderer,(i+1)*taille_cell,j*taille_cell,(i+1)*taille_cell,(j+1)*taille_cell); //mur à l'est
SDL_RenderDrawLine(renderer,i1*taille_cell+50,j1*taille_cell+50,(i1+1)*taille_cell+50,j1*taille_cell+50); //mur au nord
if ((x!=2) && (x!=3) && (x!=6) && (x!=7) && (x!=10) && (x!=11) && (x!=14) && (x!=15))
SDL_RenderDrawLine(renderer,i1*taille_cell+50,(j1+1)*taille_cell+50,(i1+1)*taille_cell+50,(j1+1)*taille_cell+50); //mur au sud
if ((x!=4) && (x!=5) && (x!=6) && (x!=7) && (x!=12) && (x!=13) && (x!=14) && (x!=15))
SDL_RenderDrawLine(renderer,(i1+1)*taille_cell+50,j1*taille_cell+50,(i1+1)*taille_cell+50,(j1+1)*taille_cell+50); //mur à l'est
if (x<8)
SDL_RenderDrawLine(renderer,i1*taille_cell+50,j1*taille_cell+50,i1*taille_cell+50,(j1+1)*taille_cell+50); //mur à l'ouest
noeud+=1;
} }
} }
SDL_RenderPresent(renderer);
SDL_Delay(3000);
SDL_RenderClear(renderer);
} }
int min(int a, int b)
{
if (a>b)
return b;
else
return a;
}
int main () int main ()
...@@ -71,30 +71,32 @@ int main () ...@@ -71,30 +71,32 @@ int main ()
return EXIT_FAILURE; return EXIT_FAILURE;
} }
int width = 800; SDL_DisplayMode screen;
int height =900; SDL_GetCurrentDisplayMode(0,&screen);
SDL_Window *window; SDL_Window *window;
window = SDL_CreateWindow("SDL2 Programme 0.1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,width, height, SDL_WINDOW_RESIZABLE); window = SDL_CreateWindow("SDL2 Programme 0.1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,screen.w,screen.h, SDL_WINDOW_RESIZABLE);
if (window == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError()); if (window == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError());
SDL_SetWindowTitle(window, "Mon_chef d'oeuvre"); SDL_SetWindowTitle(window, "Mon_chef d'oeuvre");
SDL_Renderer *renderer; SDL_Renderer *renderer;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); /* SDL_RENDERER_SOFTWARE */ renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); /* SDL_RENDERER_SOFTWARE */
if (renderer == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError()); if (renderer == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError());
int running=1; int running=1;
srand(time(0)); srand(time(0));
int noeuds=N*P; int noeuds=N*P;
int nb_aretes; int nb_aretes=2*N*P-N-P;
int **tab; int **tab;
graph_t * graph=creer_graph(noeuds,100); int cours=0;
partition_t * part=creer(noeuds); int taille_cell=min(screen.w/(P+2),screen.h/(N+2));
nb_aretes=generation(graph,4,5); printf("%d \n", taille_cell);
graph_t * graph=creer_graph(noeuds,nb_aretes);
generation(graph);
graph=Fisher(graph,nb_aretes); graph=Fisher(graph,nb_aretes);
affiche_graph_couple(graph,noeuds,nb_aretes); //printf("%d \n", nb_aretes);
graph=kruskal(graph,noeuds,nb_aretes,&cours); graph=kruskal(graph,noeuds,nb_aretes,&cours);
affiche_graph_couple(graph,noeuds,nb_aretes); //printf("cours %d\n",cours);
tab=tableau_ligne(graph,nb_aretes); // affiche_graph_couple(graph,noeuds,cours);
tab=tableau_ligne(graph,cours);
SDL_Event event; SDL_Event event;
while (running) while (running)
...@@ -112,21 +114,17 @@ int main () ...@@ -112,21 +114,17 @@ int main ()
case SDL_WINDOWEVENT_CLOSE: case SDL_WINDOWEVENT_CLOSE:
running = 0; running = 0;
break; break;
case SDL_WINDOWEVENT_SIZE_CHANGED: default:
width = event.window.data1;
height = event.window.data2;
break;
case SDL_WINDOWEVENT_EXPOSED:
break; break;
} }
break; break;
break; break;
} }
afficherEcranIntelligemment(renderer,tab,taille_cell);
SDL_RenderPresent(renderer);
SDL_Delay(10);
SDL_RenderClear(renderer);
} }
afficherEcranIntelligemment(renderer,tab,100);
SDL_RenderClear(renderer);
SDL_Delay(30);
SDL_RenderPresent(renderer);
} }
end_sdl(1, "Normal ending", window, renderer); end_sdl(1, "Normal ending", window, renderer);
return 1; return 1;
......
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
#include<SDL2/SDL.h> #include<SDL2/SDL.h>
#include "kruskal.h" #include "kruskal.h"
#include <math.h>
void end_sdl(char ok,char const* msg,SDL_Window* window, SDL_Renderer* renderer); void end_sdl(char ok,char const* msg,SDL_Window* window, SDL_Renderer* renderer);
void afficheEcranIntelligement(SDL_Renderer*,int**,int); void afficheEcranIntelligement(SDL_Renderer*,int**,int);
int min(int , int);
int main(); int main();
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment