Skip to content
Snippets Groups Projects
Commit 2a77326d authored by Taha Belkhiri's avatar Taha Belkhiri
Browse files

modification detection etat stable/cycle

parent 814e3cba
Branches
No related tags found
No related merge requests found
No preview for this file type
...@@ -5,6 +5,7 @@ int MAPSIZE = 20; ...@@ -5,6 +5,7 @@ int MAPSIZE = 20;
int **map; int **map;
int ***mapList; int ***mapList;
int mapListSize = 0;
void allocateMap() void allocateMap()
{ {
...@@ -59,62 +60,30 @@ void writeMap(char *filename) ...@@ -59,62 +60,30 @@ void writeMap(char *filename)
fclose(f); fclose(f);
} }
int **saveMapState()
{
int **mapCopy = malloc(MAPSIZE * sizeof(int *));
for (int i = 0; i < MAPSIZE; i++)
{
mapCopy[i] = malloc(MAPSIZE * sizeof(int));
}
for (int i = 0; i < MAPSIZE; i++)
{
for (int j = 0; j < MAPSIZE; j++)
{
mapCopy[i][j] = map[i][j];
}
}
return mapCopy;
}
void addMapToList(int **map) void addMapToList(int **map)
{ {
int i = 0; mapList[mapListSize] = map;
while (mapList[i] != NULL) mapListSize++;
{
i++;
}
mapList[i] = map;
} }
void checkForCycle() void checkForCycle()
{ {
// count number of maps saved for (int i = 0; i < mapListSize; i++)
int i = 0;
while (mapList[i] != NULL)
{ {
i++; int cycle = 1;
}
int j = 0; int j = 0;
for (j = 0; j < i; j++) while (cycle && j < MAPSIZE)
{ {
int cycle = 1;
// compare values of maps
int k = 0; int k = 0;
for (k = 0; k < MAPSIZE; k++) while (cycle && k < MAPSIZE)
{
for (int l = 0; l < MAPSIZE; l++)
{ {
if (mapList[j][k][l] != map[k][l]) if (mapList[i][j][k] != map[j][k])
{ {
cycle = 0; cycle = 0;
} }
k++;
} }
} j++;
if (cycle == 1)
{
printf("Cycle found!\n");
break;
} }
} }
} }
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
extern int MAPSIZE; extern int MAPSIZE;
extern int ** map; extern int ** map;
extern int *** mapList; extern int *** mapList;
extern int mapListSize;
void printMap(); void printMap();
void initMap(); void initMap();
......
...@@ -146,6 +146,8 @@ void drawStable(){ ...@@ -146,6 +146,8 @@ void drawStable(){
SDL_Rect titleRect = {ScreenDimension.w/2 - titleWidth/2, ScreenDimension.h/2 - titleHeight, titleWidth, titleHeight}; SDL_Rect titleRect = {ScreenDimension.w/2 - titleWidth/2, ScreenDimension.h/2 - titleHeight, titleWidth, titleHeight};
SDL_RenderCopy(renderer, texture, NULL, &titleRect); SDL_RenderCopy(renderer, texture, NULL, &titleRect);
SDL_RenderPresent(renderer);
} }
void MainLoop(){ void MainLoop(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment