Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int celulas (int pos_x,int pos_y,bool mat2[20][80]){
- //la funcion me devuelve la cantidad de celulas vecinas
- int vecinas;
- bool limites;
- int i;
- int j;
- vecinas=0;
- i=0;
- j=0;
- for (int i=-1;i<2; i++){
- for (int j=-1;j<2; j++){
- if ((pos_x+i)>=20 || (pos_x+i)<0 || (pos_y+j)>=80 || (pos_y+j)<0){
- limites=false; //Me fijo si estoy o no dentro de los limites de la matriz
- }else{
- limites=true;
- }
- if (limites==true){
- if(!(i == 0 && j == 0)){
- if (mat2[pos_x+i][pos_y+j]==true){
- vecinas++; //Si estoy dentro de los limites, miro las vecinas y aumento las variables
- }
- }
- }
- }
- }
- return vecinas;
- }
- void ejecutar(bool mat[20][80]){
- int pos_x;
- int pos_y;
- int turnos;
- int turnosEleg;
- int vivas;
- double muertas;
- double nacimientos;
- bool congelado;
- congelado=true;
- turnos=0;
- bool mat2[20][80]={};
- do {
- cout << "Ingrese la cantidad de turnos " << endl;
- cout << " > ";
- cin >> turnosEleg;
- if(turnosEleg>10000)
- cout<< "Limite de turnos superado "<<endl;
- } while(turnosEleg>10000);
- do {
- nacimientos=0;
- vivas=0;
- muertas=0;
- //copio la matriz original en otra,la cual uso para comparar
- for (int i=0;i<20; i++){
- for (int j=0;j<80; j++){
- mat2[i][j]=mat[i][j];
- }
- }
- for (int i=0;i<20; i++){
- for (int j=0;j<80; j++){
- if(mat2[i][j]==false && celulas (i,j, mat2)==3){
- mat[i][j]=true;
- vivas++;
- nacimientos++;
- congelado=false;
- } else if (mat2[i][j]==true && ( celulas (i,j, mat2)==3 || celulas (i,j, mat2)==2)){
- mat[i][j]=true;
- vivas++;
- } else if (mat2[i][j]==true && ((celulas(i,j,mat2)>3) || celulas(i,j,mat2)<2)){
- muertas++;
- mat[i][j]=false;
- congelado=false;
- }
- else {
- mat[i][j]=false;
- }
- }
- }
- turnos++;
- } while(turnos<turnosEleg);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement