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)
{
mapList[mapListSize] = map;
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;
void printMap();
void initMap();
void writeMap(char* filename);
void checkForCycle();
void addMapToList(int ** map);
int ** saveMapState();
......
......@@ -126,17 +126,8 @@ void drawColumns(){
SDL_RenderCopy(renderer, columnTexture, NULL, &rightRect);
}
void drawGame(){
SDL_RenderClear(renderer);
drawBackground();
drawBackground2();
drawMap();
drawColumns();
SDL_RenderPresent(renderer);
}
void drawStable(){
char str[20] = "Stable state reached";
char str[21] = "Stable state reached";
SDL_Color textColor = {0, 0, 0};
SDL_Surface * surface = TTF_RenderText_Solid(RobotoFont, str, textColor);
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
......@@ -150,6 +141,18 @@ void drawStable(){
SDL_RenderPresent(renderer);
}
void drawGame(){
SDL_RenderClear(renderer);
drawBackground();
drawBackground2();
drawMap();
drawColumns();
if (stable){
drawStable();
}
SDL_RenderPresent(renderer);
}
void MainLoop(){
CreateWindow();
......
......@@ -2,6 +2,7 @@
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 stable;
int survivingNeighbors(int x, int y){
int count = 0;
......@@ -17,7 +18,7 @@ int survivingNeighbors(int x, int y){
void updateMap(){
int newMap[MAPSIZE][MAPSIZE];
int stable = 1;
stable = 1;
for (int i=0; i<MAPSIZE; i++){
for (int j=0; j<MAPSIZE; j++){
int count = survivingNeighbors(j, i);
......@@ -38,16 +39,10 @@ void updateMap(){
}
}
if (stable){
drawStable();
}
for (int i=0; i<MAPSIZE; i++){
for (int j=0; j<MAPSIZE; j++){
map[i][j] = newMap[i][j];
}
}
addMapToList(map);
}
......@@ -7,6 +7,7 @@
#define NB_RULES 9
extern int stable;
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