From 991f3db6745173122818d383dc8b808bc91e1d92 Mon Sep 17 00:00:00 2001 From: Taha Belkhiri <belkhiri.taha53@gmail.com> Date: Tue, 21 Jun 2022 11:40:08 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20detection=20de=20cycles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- travail_individuel/Belkhiri/GameOfLife/run | Bin 23672 -> 23856 bytes .../Belkhiri/GameOfLife/src/map.c | 39 ++++++++++++++++++ .../Belkhiri/GameOfLife/src/map.h | 4 ++ .../Belkhiri/GameOfLife/src/utility.c | 15 +++++++ 4 files changed, 58 insertions(+) diff --git a/travail_individuel/Belkhiri/GameOfLife/run b/travail_individuel/Belkhiri/GameOfLife/run index b4c3dc621abb0fa478779fdf9a4734e610cf775a..87257857f689c489c5941519e96c548f7a7f12f9 100755 GIT binary patch delta 5438 zcmZWt3sh9q8a`*>01`TY;D{&;Z%`g0Vp3Y79y<#7NT^Ix=Q5P0<_q%?MYqv%I#TAo zwoI)hEi|*bKBijc@+zn~YOO9>KCWqE7j0AoL@lnDJoo$eIRnVuYjOU)|L^-Bd+&em zbB5Nv;;wz-+GNv$qWAh=>eg4_P43G=#q_`he)@2MpKF|$F2*XE`nap~6?MI@$TpgO z2%FG0_+~-jp`qrff7^BVK*YCu6UNlI%6#H|#q+L8|F463SOh_-=stss;fq`)VKYVX zB0C!XU3BpyfSm5V<j-@}Bna0w!M9Q|{HX{i?zndKdQ3F=<*;T;iuf~YvP83--lxT@ zE_1}sqC#1?<tnnhmW6>^-opD~=&MCls=UQ{#_9G{|EXzC`Ex~;{*_I@7Nz)<QuC{i zBGxJ@5!ryq81XnOh_v`uDa9wiU~?kl+WYGx<Dx$t3`<|rs_N1t#rca;(`Zsuxf-?x z|7@hS+~|{c^UgDhc*5<wmhy4PTSQf|!$Xd|#k}U?eNA)7RZvahsw(rE15ml;%|yOY z?3Oq1PM+etq|`JakhGbi7j5p6_Xd4zQp7`)O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Znk#hcC6PQhJC+RGA0g~qNP-?n`9IW(tpfl6 diff --git a/travail_individuel/Belkhiri/GameOfLife/src/map.c b/travail_individuel/Belkhiri/GameOfLife/src/map.c index 0250446..3d66af1 100644 --- a/travail_individuel/Belkhiri/GameOfLife/src/map.c +++ b/travail_individuel/Belkhiri/GameOfLife/src/map.c @@ -4,6 +4,8 @@ int MAPSIZE = 20; int ** map; +int *** mapList; + void allocateMap(){ map = malloc(MAPSIZE * sizeof(int*)); for(int i = 0; i < MAPSIZE; i++){ @@ -11,9 +13,14 @@ void allocateMap(){ } } +void allocateMapList(int SIZE){ + mapList = malloc(SIZE * sizeof(int**)); +} + void initMap() { allocateMap(); + allocateMapList(100); for(int i = 0; i < MAPSIZE; i++){ for(int j = 0; j < MAPSIZE; j++){ map[i][j] = 0; @@ -41,4 +48,36 @@ void writeMap(char* filename){ fprintf(f, "\n"); } 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; +} + +void checkForCycle(){ + int i = 0; + while(mapList[i] != NULL){ + if(mapList[i] == map){ + printf("Cycle detected at iteration: %d\n", i); + return; + } + i++; + } } \ No newline at end of file diff --git a/travail_individuel/Belkhiri/GameOfLife/src/map.h b/travail_individuel/Belkhiri/GameOfLife/src/map.h index 6ba8681..ec0e592 100644 --- a/travail_individuel/Belkhiri/GameOfLife/src/map.h +++ b/travail_individuel/Belkhiri/GameOfLife/src/map.h @@ -5,9 +5,13 @@ extern int MAPSIZE; extern int ** map; +extern int *** mapList; void printMap(); void initMap(); void writeMap(char* filename); +void checkForCycle(); +void addMapToList(int ** map); +int ** saveMapState(); #endif \ No newline at end of file diff --git a/travail_individuel/Belkhiri/GameOfLife/src/utility.c b/travail_individuel/Belkhiri/GameOfLife/src/utility.c index 0fd5618..2eab021 100644 --- a/travail_individuel/Belkhiri/GameOfLife/src/utility.c +++ b/travail_individuel/Belkhiri/GameOfLife/src/utility.c @@ -17,6 +17,7 @@ int survivingNeighbors(int x, int y){ void updateMap(){ int newMap[MAPSIZE][MAPSIZE]; + int stable = 1; for (int i=0; i<MAPSIZE; i++){ for (int j=0; j<MAPSIZE; j++){ int count = survivingNeighbors(j, i); @@ -30,10 +31,24 @@ void updateMap(){ } } } + + for (int i=0; i<MAPSIZE; i++){ + for (int j=0; j<MAPSIZE; j++){ + if (newMap[j][i] != map[j][i]) stable = 0; + } + } + + if (stable){ + printf("Stable state reached.\n"); + } + for (int i=0; i<MAPSIZE; i++){ for (int j=0; j<MAPSIZE; j++){ map[i][j] = newMap[i][j]; } } + + addMapToList(map); + checkForCycle(); } -- GitLab