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;
int **map;
int ***mapList;
int mapListSize = 0;
void allocateMap()
{
......@@ -59,62 +60,30 @@ void writeMap(char *filename)
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)
{
int i = 0;
while (mapList[i] != NULL)
{
i++;
}
mapList[i] = map;
mapList[mapListSize] = map;
mapListSize++;
}
void checkForCycle()
{
// count number of maps saved
int i = 0;
while (mapList[i] != NULL)
for (int i = 0; i < mapListSize; i++)
{
i++;
}
int cycle = 1;
int j = 0;
for (j = 0; j < i; j++)
while (cycle && j < MAPSIZE)
{
int cycle = 1;
// compare values of maps
int k = 0;
for (k = 0; k < MAPSIZE; k++)
{
for (int l = 0; l < MAPSIZE; l++)
while (cycle && k < MAPSIZE)
{
if (mapList[j][k][l] != map[k][l])
if (mapList[i][j][k] != map[j][k])
{
cycle = 0;
}
k++;
}
}
if (cycle == 1)
{
printf("Cycle found!\n");
break;
j++;
}
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@
extern int MAPSIZE;
extern int ** map;
extern int *** mapList;
extern int mapListSize;
void printMap();
void initMap();
......
......@@ -146,6 +146,8 @@ void drawStable(){
SDL_Rect titleRect = {ScreenDimension.w/2 - titleWidth/2, ScreenDimension.h/2 - titleHeight, titleWidth, titleHeight};
SDL_RenderCopy(renderer, texture, NULL, &titleRect);
SDL_RenderPresent(renderer);
}
void MainLoop(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment