Skip to content
Snippets Groups Projects
Commit 41475c4f authored by belkhiritaha's avatar belkhiritaha
Browse files

detection de cycles ne marche que pour des MAPSIZE < 7

parent 3855d640
Branches
No related tags found
No related merge requests found
CC=gcc CC=gcc
LDFLAG=$(shell sdl2-config --cflags --libs) -lm -lSDL2_ttf -D_REENTRANT -lSDL2_image -pthread LDFLAG=$(shell sdl2-config --cflags --libs) -Wall -Wextra -lm -lSDL2_ttf -D_REENTRANT -lSDL2_image -pthread
CFLAG=-Wall $(shell sdl2-config --cflags --libs) CFLAG=-Wall $(shell sdl2-config --cflags --libs)
EXEC=run EXEC=run
......
No preview for this file type
...@@ -51,14 +51,14 @@ void writeMap(char *filename) ...@@ -51,14 +51,14 @@ void writeMap(char *filename)
fclose(f); fclose(f);
} }
int MapToBinary(int ** map) long long int MapToBinary(int ** map)
{ {
int binary = 0; long long int binary = 0;
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++)
{ {
binary += map[i][j] * pow(2, (i * MAPSIZE + j)); binary += (long long int)map[i][j] * powl(2, (i * MAPSIZE + j));
} }
} }
return binary; return binary;
......
...@@ -9,6 +9,6 @@ extern int ** map; ...@@ -9,6 +9,6 @@ extern int ** map;
void printMap(); void printMap();
void initMap(); void initMap();
void writeMap(char* filename); void writeMap(char* filename);
int MapToBinary(int ** map); long long int MapToBinary(int ** map);
#endif #endif
\ No newline at end of file
...@@ -4,7 +4,7 @@ int surviveRule[NB_RULES] = {0, 0, 1, 1, 0, 0, 0, 0, 0}; ...@@ -4,7 +4,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 bornRule[NB_RULES] = {0, 0, 0, 1, 0, 0, 0, 0, 0};
int stable; int stable;
int BinaryList[LIST_SIZE]; long long int BinaryList[LIST_SIZE];
int BinaryListSize; int BinaryListSize;
int survivingNeighbors(int x, int y){ int survivingNeighbors(int x, int y){
...@@ -18,16 +18,28 @@ int survivingNeighbors(int x, int y){ ...@@ -18,16 +18,28 @@ int survivingNeighbors(int x, int y){
return count; return count;
} }
void addBinaryToList(int binary){ void addBinaryToList(long long int binary){
if (BinaryListSize == LIST_SIZE) return; if (BinaryListSize == LIST_SIZE) return;
BinaryList[BinaryListSize] = binary; BinaryList[BinaryListSize] = binary;
BinaryListSize++; BinaryListSize++;
} }
void printBinaryList(){
for (int i=0; i<BinaryListSize; i++){
printf("%lld ", BinaryList[i]);
}
printf("\n");
}
void checkForCycle(){ void checkForCycle(){
int i = 0; int i = 0;
while (i < BinaryListSize){ printBinaryList();
while (i < BinaryListSize-1){
if (BinaryList[i] == BinaryList[BinaryListSize - 1]){ if (BinaryList[i] == BinaryList[BinaryListSize - 1]){
printf("%lld\n %lld\n", BinaryList[i], BinaryList[BinaryListSize - 1]);
printf("Cycle detected!\n"); printf("Cycle detected!\n");
return; return;
} }
...@@ -40,7 +52,7 @@ void updateMap(){ ...@@ -40,7 +52,7 @@ void updateMap(){
int newMap[MAPSIZE][MAPSIZE]; int newMap[MAPSIZE][MAPSIZE];
stable = 1; stable = 1;
int binary = MapToBinary(map); long long int binary = MapToBinary(map);
addBinaryToList(binary); addBinaryToList(binary);
for (int i=0; i<MAPSIZE; i++){ for (int i=0; i<MAPSIZE; i++){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment