Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 2d.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "time.h"
- #include <iostream>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- srand(time(NULL));
- int tab[20][20];
- int tab2[20][20];
- for(int i=0;i<20;i++)
- {
- for(int j=0;j<20;j++)
- {
- tab[i][j]=rand()%2;
- }
- }
- // tab[10][10]=1;
- //tab[11][10]=1;
- //tab[10][11]=1;
- //tab[11][11]=1;
- for(int i=0;i<20;i++)
- {
- for(int j=0;j<20;j++)
- {
- tab2[i][j]=tab[i][j];
- }
- }
- for(int i=0;i<20;i++)
- {
- for(int j=0;j<20;j++)
- {
- cout << tab[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- int z=0;
- while(z<5)
- {
- for(int i=1;i<19;i++)
- {
- for(int j=1;j<19;j++)
- {
- if(tab[i][j]==1)
- {
- int licz=0;
- if(tab[i-1][j-1]==1)
- licz++;
- if(tab[i-1][j]==1)
- licz++;
- if(tab[i-1][j+1]==1)
- licz++;
- if(tab[i][j-1]==1)
- licz++;
- if(tab[i][j+1]==1)
- licz++;
- if(tab[i+1][j-1]==1)
- licz++;
- if(tab[i+1][j]==1)
- licz++;
- if(tab[i+1][j+1]==1)
- licz++;
- //cout << "licznik: " << licz << endl;
- if(licz==0 || licz==1 || licz==4)
- {
- tab2[i][j]=0;
- //cout << "zmieniam wartosc 1 na 0 w komorce" << i << " " << j << endl;
- }
- }
- if(tab[i][j]==0)
- {
- int licz=0;
- if(tab[i-1][j-1]==1)
- licz++;
- if(tab[i-1][j]==1)
- licz++;
- if(tab[i-1][j+1]==1)
- licz++;
- if(tab[i][j-1]==1)
- licz++;
- if(tab[i][j+1]==1)
- licz++;
- if(tab[i+1][j-1]==1)
- licz++;
- if(tab[i+1][j]==1)
- licz++;
- if(tab[i+1][j+1]==1)
- licz++;
- if(licz==3)
- {
- tab2[i][j]=1;
- }
- }
- }
- }
- for(int i=0;i<20;i++)
- {
- for(int j=0;j<20;j++)
- {
- tab[i][j]=tab2[i][j];
- }
- }
- for(int i=0;i<20;i++)
- {
- for(int j=0;j<20;j++)
- {
- cout << tab[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- cout << endl;
- cout << endl;
- z++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement