/*
COPYRIGHT 2005 MUSTAFA BASARAN
BU ALGORITMANIN TUM HAKLARI MUSTAFA BASARANA AITTIR
BU PROGRAM YAZILANA KADAR EMEK HARCANMIS ALIN TERI DOKULMUSTUR
ISIM BELIRTILMEDEN COGALTILMASI KANUNLARA AYKIRIDIR
TESPIT EDILDIGI TAKDIRDE HAKKINDA CEZAI ISLEM UYGULANACAKTIR
*/
#include
using std::cin;
using std::cout;
using std::endl;
class grid {
private:
bool alive;
int n;
bool next;
public:
grid(){ alive=false;next=false;n=0;}
bool getstat() { return alive;}
void setstat(bool a) { alive=a;}
void inc(){n++;}
int getn(){ return n;}
void setnext(bool a){ next=a;}
bool getnext() { return next; }
void resetn(){ n=0;}
};
static grid* square[10][10];
make()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
grid* g=new grid();
square[i][j]=g;
}
}
}
caln()
{
for(int x=0;x<10;x++)
{
for(int y=0;y<10;y++)
{
square[x][y]->resetn();
}
}
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(i!=9) { if(square[i+1][j]->getstat()) square[i][j]->inc();}
if(i!=9 && j!=9){ if(square[i+1][j+1]->getstat()) square[i][j]->inc();}
if(i!=9 && j!=0) { if(square[i+1][j-1]->getstat()) square[i][j]->inc();}
if(j!=9){ if(square[i][j+1]->getstat()) square[i][j]->inc();}
if(j!=0){ if(square[i][j-1]->getstat()) square[i][j]->inc();}
if(i!=0){ if(square[i-1][j]->getstat()) square[i][j]->inc();}
if(i!=0 && j!=9){ if(square[i-1][j+1]->getstat()) square[i][j]->inc();}
if(i!=0 && j!=0){ if(square[i-1][j-1]->getstat()) square[i][j]->inc();}
}
}
}
int numlive()
{
int n=0;
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(square[i][j]->getstat()) n++;
}
}
return n;
}
void isitlive()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(square[i][j]->getstat()==false && square[i][j]->getn()==3) square[i][j]->setnext(true);
if(square[i][j]->getstat()==true && (square[i][j]->getn()==2 || square[i][j]->getn()==3)) square[i][j]->setnext(true);
if(square[i][j]->getstat()==true && (square[i][j]->getn()<2 || square[i][j]->getn()>=4)) square[i][j]->setnext(false);
}
}
}
void nextpos()
{
caln();
isitlive();
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(square[i][j]->getnext()) square[i][j]->setstat(true);
else square[i][j]->setstat(false);
}
}
}
show()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(square[i][j]->getstat()) printf("o");
else printf(".");
if(j==9) printf("\n");
}
}
}
void main()
{
char a;
make();
square[4][4]->setstat(true);
square[5][5]->setstat(true);
square[6][6]->setstat(true);
square[6][4]->setstat(true);
square[5][3]->setstat(true);
square[5][4]->setstat(true);
while(1)
{
show();
cout< nextpos();
cout<<"devam?[e][h]";
cin>>a;
if(a=='h' || a=='H') exit(1);
}
}