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
No related branches found
No related tags found
No related merge requests found
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)
EXEC=run
......
No preview for this file type
......@@ -51,14 +51,14 @@ void writeMap(char *filename)
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 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;
......
......@@ -9,6 +9,6 @@ extern int ** map;
void printMap();
void initMap();
void writeMap(char* filename);
int MapToBinary(int ** map);
long long int MapToBinary(int ** map);
#endif
\ No newline at end of file
......@@ -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 stable;
int BinaryList[LIST_SIZE];
long long int BinaryList[LIST_SIZE];
int BinaryListSize;
int survivingNeighbors(int x, int y){
......@@ -18,16 +18,28 @@ int survivingNeighbors(int x, int y){
return count;
}
void addBinaryToList(int binary){
void addBinaryToList(long long int binary){
if (BinaryListSize == LIST_SIZE) return;
BinaryList[BinaryListSize] = binary;
BinaryListSize++;
}
void printBinaryList(){
for (int i=0; i<BinaryListSize; i++){
printf("%lld ", BinaryList[i]);
}
printf("\n");
}
void checkForCycle(){
int i = 0;
while (i < BinaryListSize){
printBinaryList();
while (i < BinaryListSize-1){
if (BinaryList[i] == BinaryList[BinaryListSize - 1]){
printf("%lld\n %lld\n", BinaryList[i], BinaryList[BinaryListSize - 1]);
printf("Cycle detected!\n");
return;
}
......@@ -40,7 +52,7 @@ void updateMap(){
int newMap[MAPSIZE][MAPSIZE];
stable = 1;
int binary = MapToBinary(map);
long long int binary = MapToBinary(map);
addBinaryToList(binary);
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