#include<bits/stdc++.h>
 #include<conio.h>
 using namespace std;
 int x,y,l;
 bool s,c[12][12],flag;
 char a[12][12],b[12][12],f;
 void csh();
 void _cout();
 void _cin();
 void _yiwei();
 int statistics_1(int j,int i);
 int statistics_2(int j,int i);
 void around(int j,int i);
 int main(){
     csh();
     while(1){
         _cout();
         if(s){
             printf("Game over!\n");
             break;
         }
         if(l==0){
             printf("Win!\n");
             break;
         }
         _cin();
         _yiwei();
     }
     return 0;
 }
 void csh(){
     l=20;s=false;
     for(int i=0;i<=11;i++)
         for(int j=0;j<=11;j++)
             a[i][j]='#',b[i][j]='0',c[i][j]=true;
     srand(time(NULL));
     for(int i=0;i<20;){
         x=rand()%10+1;y=rand()%10+1;
         if(b[y][x]!='*')    i++,b[y][x]='*';
     }
     for(int i=1;i<=10;i++)
         for(int j=1;j<=10;j++)
             if(b[i][j]!='*')
                 b[i][j]+=(b[i+1][j]=='*')+(b[i-1][j]=='*')+(b[i][j+1]=='*')+(b[i][j-1]=='*')+(b[i+1][j+1]=='*')+(b[i+1][j-1]=='*')+(b[i-1][j+1]=='*')+(b[i-1][j-1]=='*');
     x=5,y=5;
     return;
 }
 void _cout(){
     system("cls");
     for(int i=1;i<=10;i++){
         for(int j=1;j<=10;j++){
             if(i==y&&j==x)  printf("X ");
                 else if(a[i][j]=='0')    printf("/ ");
                 else   printf("%c ",a[i][j]);
             }
             printf("\n");
         }
     printf("                *:%d\n",l);
     return;
 }
 void _cin(){
     f=getch();
     switch(f){
         case 'W':case 'w':if(y>1) y--;break;
         case 'S':case 's':if(y<10)    y++;break;
         case 'A':case 'a':if(x>1) x--;break;
         case 'D':case 'd':if(x<10)    x++;break;
         case '1':if(b[y][x]=='*'&&c[y][x])l--;
                    a[y][x]='+';c[y][x]=false;
                 if(b[y][x]!='*')s=true;
                 break;
         case ' ':a[y][x]=b[y][x];c[y][x]=false;
                 if(b[y][x]=='*') s=true;
                 if(statistics_1(x,y)==statistics_2(x,y)&&b[y][x]!='*') around(x,y);
                 break;
         default:break;
     }
     return;
 }
 void _yiwei(){
     if(f==' '||f=='1'){
         flag=false;
         for(int i=1;i<10;i+=2){
             for(int j=1;j<=i;j++){
                 if(y>1)  y--;
                 if(c[y][x]){
                     flag=true;break;
                 }
             }
             if(flag)    break;
             for(int j=1;j<=i;j++){
                 if(x<10) x++;
                 if(c[y][x]){
                     flag=true;break;
                 }
             }
             if(flag)    break;
             for(int j=1;j<=i+1;j++){
                 if(y<10) y++;
                 if(c[y][x]){
                     flag=true;break;
                 }
             }
             if(flag)    break;
             for(int j=1;j<=i+1;j++){
                 if(x>1)  x--;
                 if(c[y][x]){
                     flag=true;break;
                 }
             }
             if(flag)    break;
         }
     }
     return;
 }
 int statistics_1(int j,int i){
     return ((b[i+1][j]=='*')+(b[i-1][j]=='*')+(b[i][j+1]=='*')+(b[i][j-1]=='*')+(b[i+1][j+1]=='*')+(b[i+1][j-1]=='*')+(b[i-1][j+1]=='*')+(b[i-1][j-1]=='*'));
 }
 int statistics_2(int j,int i){
     return ((a[i+1][j]=='+')+(a[i-1][j]=='+')+(a[i][j+1]=='+')+(a[i][j-1]=='+')+(a[i+1][j+1]=='+')+(a[i+1][j-1]=='+')+(a[i-1][j+1]=='+')+(a[i-1][j-1]=='+'));
 }
 void around(int j,int i){
     if(b[i+1][j]!='*'&&c[i+1][j]&&statistics_1(j,i+1)==statistics_2(j,i+1)&&i<10) c[i+1][j]=false,around(j,i+1);
     if(b[i-1][j]!='*'&&c[i-1][j]&&statistics_1(j,i-1)==statistics_2(j,i-1)&&i>1) c[i-1][j]=false,around(j,i-1);
     if(b[i][j+1]!='*'&&c[i][j+1]&&statistics_1(j+1,i)==statistics_2(j+1,i)&&j<10) c[i][j+1]=false,around(j+1,i);
     if(b[i][j-1]!='*'&&c[i][j-1]&&statistics_1(j-1,i)==statistics_2(j-1,i)&&j>1) c[i][j-1]=false,around(j-1,i);
     if(b[i+1][j+1]!='*'&&c[i+1][j+1]&&statistics_1(j+1,i+1)==statistics_2(j+1,i+1)&&i<10&&j<10) c[i+1][j+1]=false,around(j+1,i+1);
     if(b[i-1][j-1]!='*'&&c[i-1][j-1]&&statistics_1(j-1,i-1)==statistics_2(j-1,i-1)&&i>1&&j>1) c[i-1][j-1]=false,around(j-1,i-1);
     if(b[i-1][j+1]!='*'&&c[i-1][j+1]&&statistics_1(j+1,i-1)==statistics_2(j+1,i-1)&&i>1&&j<10) c[i-1][j+1]=false,around(j+1,i-1);
     if(b[i+1][j-1]!='*'&&c[i+1][j-1]&&statistics_1(j-1,i+1)==statistics_2(j-1,i+1)&&i<10&&j>1) c[i+1][j-1]=false,around(j-1,i+1);
     if(b[i+1][j]!='*')  a[i+1][j]=b[i+1][j],c[i+1][j]=false;
     if(b[i-1][j]!='*')  a[i-1][j]=b[i-1][j],c[i-1][j]=false;
     if(b[i][j+1]!='*')  a[i][j+1]=b[i][j+1],c[i][j+1]=false;
     if(b[i][j-1]!='*')  a[i][j-1]=b[i][j-1],c[i][j-1]=false;
     if(b[i+1][j+1]!='*')    a[i+1][j+1]=b[i+1][j+1],c[i+1][j+1]=false;
     if(b[i-1][j-1]!='*')    a[i-1][j-1]=b[i-1][j-1],c[i-1][j-1]=false;
     if(b[i-1][j+1]!='*')    a[i-1][j+1]=b[i-1][j+1],c[i-1][j+1]=false;
     if(b[i+1][j-1]!='*')    a[i+1][j-1]=b[i+1][j-1],c[i+1][j-1]=false;
     return;
 }










