Skip to content
Snippets Groups Projects
Commit 906425d4 authored by belkhiritaha's avatar belkhiritaha
Browse files

fin detection etat stable / nouvelle methode pour la detection des cycles

parent 2a77326d
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -64,26 +64,4 @@ void addMapToList(int **map) ...@@ -64,26 +64,4 @@ void addMapToList(int **map)
{ {
mapList[mapListSize] = map; mapList[mapListSize] = map;
mapListSize++; mapListSize++;
}
void checkForCycle()
{
for (int i = 0; i < mapListSize; i++)
{
int cycle = 1;
int j = 0;
while (cycle && j < MAPSIZE)
{
int k = 0;
while (cycle && k < MAPSIZE)
{
if (mapList[i][j][k] != map[j][k])
{
cycle = 0;
}
k++;
}
j++;
}
}
} }
\ No newline at end of file
...@@ -11,7 +11,6 @@ extern int mapListSize; ...@@ -11,7 +11,6 @@ extern int mapListSize;
void printMap(); void printMap();
void initMap(); void initMap();
void writeMap(char* filename); void writeMap(char* filename);
void checkForCycle();
void addMapToList(int ** map); void addMapToList(int ** map);
int ** saveMapState(); int ** saveMapState();
......
...@@ -126,17 +126,8 @@ void drawColumns(){ ...@@ -126,17 +126,8 @@ void drawColumns(){
SDL_RenderCopy(renderer, columnTexture, NULL, &rightRect); SDL_RenderCopy(renderer, columnTexture, NULL, &rightRect);
} }
void drawGame(){
SDL_RenderClear(renderer);
drawBackground();
drawBackground2();
drawMap();
drawColumns();
SDL_RenderPresent(renderer);
}
void drawStable(){ void drawStable(){
char str[20] = "Stable state reached"; char str[21] = "Stable state reached";
SDL_Color textColor = {0, 0, 0}; SDL_Color textColor = {0, 0, 0};
SDL_Surface * surface = TTF_RenderText_Solid(RobotoFont, str, textColor); SDL_Surface * surface = TTF_RenderText_Solid(RobotoFont, str, textColor);
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface); SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
...@@ -150,6 +141,18 @@ void drawStable(){ ...@@ -150,6 +141,18 @@ void drawStable(){
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
void drawGame(){
SDL_RenderClear(renderer);
drawBackground();
drawBackground2();
drawMap();
drawColumns();
if (stable){
drawStable();
}
SDL_RenderPresent(renderer);
}
void MainLoop(){ void MainLoop(){
CreateWindow(); CreateWindow();
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
int surviveRule[NB_RULES] = {0, 0, 1, 1, 0, 0, 0, 0, 0}; int surviveRule[NB_RULES] = {0, 0, 1, 1, 0, 0, 0, 0, 0};
int bornRule[NB_RULES] = {0, 0, 0, 1, 0, 0, 0, 0, 0}; int bornRule[NB_RULES] = {0, 0, 0, 1, 0, 0, 0, 0, 0};
int stable;
int survivingNeighbors(int x, int y){ int survivingNeighbors(int x, int y){
int count = 0; int count = 0;
...@@ -17,7 +18,7 @@ int survivingNeighbors(int x, int y){ ...@@ -17,7 +18,7 @@ int survivingNeighbors(int x, int y){
void updateMap(){ void updateMap(){
int newMap[MAPSIZE][MAPSIZE]; int newMap[MAPSIZE][MAPSIZE];
int stable = 1; stable = 1;
for (int i=0; i<MAPSIZE; i++){ for (int i=0; i<MAPSIZE; i++){
for (int j=0; j<MAPSIZE; j++){ for (int j=0; j<MAPSIZE; j++){
int count = survivingNeighbors(j, i); int count = survivingNeighbors(j, i);
...@@ -38,16 +39,10 @@ void updateMap(){ ...@@ -38,16 +39,10 @@ void updateMap(){
} }
} }
if (stable){
drawStable();
}
for (int i=0; i<MAPSIZE; i++){ for (int i=0; i<MAPSIZE; i++){
for (int j=0; j<MAPSIZE; j++){ for (int j=0; j<MAPSIZE; j++){
map[i][j] = newMap[i][j]; map[i][j] = newMap[i][j];
} }
} }
addMapToList(map);
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#define NB_RULES 9 #define NB_RULES 9
extern int stable;
void updateMap(); void updateMap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment