Skip to content
Snippets Groups Projects
Commit 8789ea6c authored by antoinemeyer5's avatar antoinemeyer5
Browse files

jeu de la vie fonctionnel

parent 18b7a2ce
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#define TAILLE_MONDE_DELIMITE 20 #define TAILLE_MONDE_DELIMITE 50
#define TAILLE_TABLEAU_REGLES 9 #define TAILLE_TABLEAU_REGLES 9
int survie[TAILLE_TABLEAU_REGLES] = {0, 0, 1, 1, 0, 0, 0, 0, 0}; int survie[TAILLE_TABLEAU_REGLES] = {0, 0, 1, 1, 0, 0, 0, 0, 0};
...@@ -139,17 +139,30 @@ int nombreVoisinsVivants(int monde[TAILLE_MONDE_DELIMITE][TAILLE_MONDE_DELIMITE] ...@@ -139,17 +139,30 @@ int nombreVoisinsVivants(int monde[TAILLE_MONDE_DELIMITE][TAILLE_MONDE_DELIMITE]
void reglesEvolutions(int monde[TAILLE_MONDE_DELIMITE][TAILLE_MONDE_DELIMITE]){ void reglesEvolutions(int monde[TAILLE_MONDE_DELIMITE][TAILLE_MONDE_DELIMITE]){
int i = 0; int i = 0;
int j = 0; int j = 0;
int mondeSuivant[TAILLE_MONDE_DELIMITE][TAILLE_MONDE_DELIMITE] = {0};
int nbrVoisinsVivants = 0; int nbrVoisinsVivants = 0;
for(i=0; i<TAILLE_MONDE_DELIMITE; i++){ for(i=0; i<TAILLE_MONDE_DELIMITE; i++){
for(j=0; j<TAILLE_MONDE_DELIMITE; j++){ for(j=0; j<TAILLE_MONDE_DELIMITE; j++){
nbrVoisinsVivants = nombreVoisinsVivants(monde, i, j); nbrVoisinsVivants = nombreVoisinsVivants(monde, i, j);
if(monde[i][j]==1 && survie[nbrVoisinsVivants]==0){ if(monde[i][j]==1 && survie[nbrVoisinsVivants]==0){
monde[i][j] = 0; mondeSuivant[i][j] = 0;
}else if(monde[i][j]==0 && naissance[nbrVoisinsVivants]==1){ }else if(monde[i][j]==0 && naissance[nbrVoisinsVivants]==1){
monde[i][j] = 1; mondeSuivant[i][j] = 1;
}else{
mondeSuivant[i][j] = monde[i][j];
} }
} }
} }
for(i=0; i<TAILLE_MONDE_DELIMITE; i++){
for(j=0; j<TAILLE_MONDE_DELIMITE; j++){
monde[i][j] = mondeSuivant[i][j];
}
}
} }
int main() { int main() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment