Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. int celulas (int pos_x,int pos_y,bool mat2[20][80]){
  2. //la funcion me devuelve la cantidad de celulas vecinas
  3.  
  4. int vecinas;
  5. bool limites;
  6. int i;
  7. int j;
  8. vecinas=0;
  9.  i=0;
  10.  j=0;
  11.  for (int i=-1;i<2; i++){
  12.    for (int j=-1;j<2; j++){
  13.      if ((pos_x+i)>=20 || (pos_x+i)<0 || (pos_y+j)>=80 || (pos_y+j)<0){
  14.         limites=false; //Me fijo si estoy o no dentro de los limites de la matriz
  15.       }else{
  16.           limites=true;
  17.         }
  18.         if (limites==true){
  19.           if(!(i == 0 && j == 0)){
  20.             if (mat2[pos_x+i][pos_y+j]==true){
  21.               vecinas++; //Si estoy dentro de los limites, miro las vecinas y aumento las variables
  22.             }
  23.           }
  24.         }
  25.     }
  26.   }
  27. return vecinas;
  28. }
  29.  
  30. void ejecutar(bool mat[20][80]){
  31.   int pos_x;
  32.   int pos_y;
  33.   int turnos;
  34.   int turnosEleg;
  35.   int vivas;
  36.   double muertas;
  37.   double nacimientos;
  38.   bool  congelado;
  39.   congelado=true;
  40.   turnos=0;
  41.   bool mat2[20][80]={};
  42.   do {
  43.     cout << "Ingrese la cantidad de turnos " << endl;
  44.     cout << " > ";
  45.     cin >> turnosEleg;
  46.     if(turnosEleg>10000)
  47.       cout<< "Limite de turnos superado "<<endl;
  48.   } while(turnosEleg>10000);
  49.     do {
  50.  
  51.       nacimientos=0;
  52.       vivas=0;
  53.       muertas=0;
  54.       //copio la matriz original en otra,la cual uso para comparar
  55.       for (int i=0;i<20; i++){
  56.         for (int j=0;j<80; j++){
  57.             mat2[i][j]=mat[i][j];
  58.           }
  59.         }
  60.  
  61.       for (int i=0;i<20; i++){
  62.         for (int j=0;j<80; j++){
  63.             if(mat2[i][j]==false && celulas (i,j, mat2)==3){
  64.               mat[i][j]=true;
  65.               vivas++;
  66.               nacimientos++;
  67.               congelado=false;
  68.  
  69.             } else if (mat2[i][j]==true && ( celulas (i,j, mat2)==3 || celulas (i,j, mat2)==2)){
  70.                 mat[i][j]=true;
  71.                 vivas++;
  72.  
  73.  
  74.             } else if (mat2[i][j]==true && ((celulas(i,j,mat2)>3) || celulas(i,j,mat2)<2)){
  75.                 muertas++;
  76.                 mat[i][j]=false;
  77.                 congelado=false;
  78.  
  79.             }
  80.              else {
  81.               mat[i][j]=false;
  82.             }
  83.  
  84.         }
  85.       }
  86.  
  87.       turnos++;
  88.  
  89.  
  90.  
  91.     } while(turnos<turnosEleg);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement