include [HTML_REMOVED]
//可替换成[HTML_REMOVED]和[HTML_REMOVED]
//YES
using namespace std;
int a[30][30],dp[30][30];
int flag[30][30];
int dx[9]={-1,-1,-1,0,0,1,1,1};
int dy[9]={-1,0,1,-1,1,-1,0,1};
int rx[9]={-2,-2,-1,1,2,2,1,-1};
int ry[9]={-1,1,2,2,1,-1,-2,-2};
int step,check;
void checksit(int n,int m){
for(int i=0;i<8;i){
int num=0;
for(int j=1;j<5;j){
if(a[n+jdx[i]][m+jdy[i]]==1) num;
if(a[n+jdx[i]][m+jdy[i]]==2) break;
}
for(int j=1;j<5;j){
if(a[n-jdx[i]][m-jdy[i]]==1) num;
if(a[n-jdx[i]][m-jdy[i]]==2) break;
}
if(num==4) {dp[n][m]+=1000; flag[n][m]==3;}
if(num==3&&a[n+4dx[i]][m+4dy[i]]==2) dp[n][m]+=10;
if(num==3&&a[n+4dx[i]][m+4dy[i]]==0) {dp[n][m]+=500; flag[n][m]==1;}
if(num==2&&a[n+3dx[i]][m+3dy[i]]==2) dp[n][m]+=1;
if(num==2&&a[n+3dx[i]][m+3dy[i]]==0) dp[n][m]+=3;
}
for(int i=0;i<8;i){
int num=0;
for(int j=1;j<5;j){
if(a[n+jdx[i]][m+jdy[i]]==2) num;
else break;
}
for(int j=1;j<5;j){
if(a[n-jdx[i]][m-jdy[i]]==2) num;
else break;
}
if(num==4) {dp[n][m]+=1000; flag[n][m]==2;}
if(num==3&&a[n+4dx[i]][m+4dy[i]]==1) dp[n][m]+=20;
if(num==3&&a[n+4dx[i]][m+4dy[i]]==0) {dp[n][m]+=500; flag[n][m]==2;}
if(num==2&&a[n+3dx[i]][m+3dy[i]]==1) dp[n][m]+=2;
if(num==2&&a[n+3dx[i]][m+3dy[i]]==0) dp[n][m]+=10;
}
for(int i=0;i<8;i){
for(int j=0;j<8;j){
if(j==i) continue;
int num=0;
for(int k=1;k<3;k){
if(a[n+kdx[j]][m+kdy[j]]==1) num;
if(a[n+kdx[i]][m+kdy[i]]==2) {num-=2;break;}
}
for(int k=1;k<3;k){
if(a[n-kdx[j]][m-kdy[j]]==1) num;
if(a[n-kdx[i]][m-kdy[i]]==2) {num-=2;break;}
}
for(int k=1;k<3;k){
if(a[n+kdx[i]][m+kdy[i]]==1) num;
if(a[n+kdx[i]][m+kdy[i]]==2) {num-=2;break;}
}
for(int k=1;k<3;k){
if(a[n-kdx[i]][m-kdy[i]]==1) num;
if(a[n-kdx[i]][m-kdy[i]]==2) {num-=2;break;}
}
if(num>=4) dp[n][m]+=80;
else if(num==3) dp[n][m]+=20;
}
}
for(int i=0;i<8;i){
for(int j=0;j<8;j){
if(j==i) continue;
int num=0;
for(int k=1;k<3;k){
if(a[n+kdx[j]][m+kdy[j]]==2) num;
if(a[n+kdx[i]][m+kdy[i]]==1) {num-=2;break;}
}
for(int k=1;k<3;k){
if(a[n-kdx[j]][m-kdy[j]]==2) num;
if(a[n-kdx[i]][m-kdy[i]]==1) {num-=2;break;}
}
for(int k=1;k<3;k){
if(a[n+kdx[i]][m+kdy[i]]==2) num;
if(a[n+kdx[i]][m+kdy[i]]==1) {num-=2;break;}
}
for(int k=1;k<3;k){
if(a[n-kdx[i]][m-kdy[i]]==2) num;
if(a[n-kdx[i]][m-kdy[i]]==1) {num-=2;break;}
}
if(num>=4) dp[n][m]+=50;
else if(num==3) dp[n][m]+=10;
}
}
for(int i=0;i<8;i){
int seti=0,setj=0;
for(int j=1;j<5;j)
if(a[n+jdx[i]][m+jdy[i]]==1) seti=j;
for(int j=1;j<5;j)
if(a[n-jdx[i]][m-jdy[i]]==1) setj=j;
if(abs(seti-setj)<=4) dp[n][m]-=30;
}
int num=0;
for(int k=0;k<8;k){
if(a[n+dx[k]][m+dy[k]]==2){
dp[n][m]+=10;
num;
}
if(a[n+dx[k]][m+dy[k]]==1) dp[n][m]+=2;
}
if(num==0)
for(int i=0;i<8;i){
if(a[n+rx[i]][m+rx[i]]==2) dp[n][m]-=20;
}
}
int judgewin(){
for(int i=1;i<=25;i){
for(int j=1;j<=25;j){
if(a[i][j]==0) continue;
int numwin=0;
for(numwin=1;numwin<=4;numwin){
if(a[i+numwin][j]!=a[i][j])
break;
}
if(numwin==5) {return a[i][j];}
numwin==0;
for(numwin=1;numwin<=4;numwin){
if(a[i][j+numwin]!=a[i][j])
break;
}
if(numwin==5) {return a[i][j];}
numwin==0;
for(numwin=1;numwin<=4;numwin){
if(a[i+numwin][j+numwin]!=a[i][j])
break;
}
if(numwin==5) {return a[i][j];}
numwin==0;
if(j>5){
for(numwin=1;numwin<=4;numwin){
if(a[i+numwin][j-numwin]!=a[i][j])
break;
}
if(numwin==5) {return a[i][j];}
}
}
}
return 0;
}
void out(){
system(“cls”);
for(int i=0;i<=24;i){
for(int j=0;j<=24;j){
if(a[i][j]!=0){
if(a[i][j]==1&&i!=0&&j!=0) printf(” O”);
else if(a[i][j]==2&&i!=0&&j!=0) printf(” X”);
else cout<[HTML_REMOVED]24||m>24){
printf(“Useless place!Try again!”);
scanf(“%d%d”,&n,&m);
}
a[n][m]=1;
dp[n][m]=0;
out();
int ans=judgewin();
if(ans==2) {printf(“Computer win!\n”); break;}
if(ans==1) {printf(“Player win!\n”); break;}
if(step>=100) {printf(“Good game!\n”);break;}
if(step==1){
dp[n+1][m+2]=100;
tempi=n+1;tempj=m+2;
}
else if(step==2){
if(a[tempi+1][tempj-1]==0) dp[tempi+1][tempj-1]=100;
else dp[tempi-1][tempj-1]=100;
}
else for(int i=1;i<=25;i){
for(int j=1;j<=25;j){
if(a[i][j]!=0) continue;
checksit(i,j);
}
}
int max=0,maxn=0,maxm=0;
for(int i=1;i<=25;i){
for(int j=1;j<=25;j){
if(max[HTML_REMOVED]=100) {printf(“Good game!\n”);break;}
}
system(“pause”);
return 0;
}