<span style="font-size:18px;">#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int clockwise[][2]={-1,0,-1,1,0,1,1,1,1,0,1,-1,0,-1,-1,-1}; //顺时针方向
void stamp(char chess[][10])
{
for(int i=1;i<9;i++)
{
for(int j=1;j<9;j++)
printf("%c",chess[i][j]);
printf("\n");
}
}
void L(char C,char chess[][10])
{
int p=0;
for(int i=1;i<9;i++)
{
for(int j=1;j<9;j++)
{
int f=0;
if(chess[i][j]=='-')
{
for(int k=0;k<8;k++)
{
int t=0,r=i,c=j;
r+=clockwise[k][0],c+=clockwise[k][1];
while(r<9&&r>0&&c<9&&c>0)
{
if(chess[r][c]==C&&t)
{
f=1;
break;
}
else if(chess[r][c]!='-'&&chess[r][c]!=C)
t++;
else
break;
r+=clockwise[k][0],c+=clockwise[k][1];
}
}
}
if(f==1)
{
if(p)
printf(" ");
p++;
printf("(%d,%d)",i,j);
}
}
}
if(p==0)
printf("No legal move.");
printf("\n");
}
void M(char *C,char chess[][10],int r,int c)
{
int f=0;
begin:;
for(int k=0;k<8;k++)
{
int t=0,x=r,y=c;
x+=clockwise[k][0],y+=clockwise[k][1];
while(x<9&&x>0&&y<9&&y>0)
{
if(chess[x][y]==*C&&t)
{
f=1;
while(1)
{
x-=clockwise[k][0],y-=clockwise[k][1];
chess[x][y]=*C;
if(r==x&&y==c)
break;
}
break;
}
else if(chess[x][y]!='-'&&chess[x][y]!=*C)
t++;
else
break;
x+=clockwise[k][0],y+=clockwise[k][1];
}
}
if(f)
{
int w1=0,b=0;
for(int i=1;i<9;i++)
{
for(int j=1;j<9;j++)
{
if(chess[i][j]=='W')
w1++;
else if(chess[i][j]=='B')
b++;
}
}
printf("Black -%3d White -%3d\n",b,w1);
}
else
{
if(*C=='W')
*C='B';
else
*C='W';
goto begin;
}
}
int main(void)
{
// freopen("C:\\Users\\5201\\Desktop\\IN.txt","r",stdin);
// freopen("C:\\Users\\5201\\Desktop\\OUT.txt","w",stdout);
int t;
scanf("%d",&t);
for(int p=0;p<t;p++)
{
char C,chess[10][10]={0};
for(int i=1;i<9;i++)
{
for(int j=1;j<9;j++)
cin>>chess[i][j];
}
cin>>C;
while(1)
{
char s[4]; //读入操作
scanf("%s",s);
if(s[0]=='L')
L(C,chess);
else if(s[0]=='M')
{
M(&C,chess,s[1]-'0',s[2]-'0');
if(C=='W')
C='B';<span style="white-space:pre"> </span>//更新游戏者
else
C='W';
}
else
{
stamp(chess);
if(p!=t-1)
printf("\n");
break;
}
}
}
return 0;
}<span style="white-space:pre"> </span>--邱新磊</span>
HUV黑白翻转棋
最新推荐文章于 2023-06-21 17:51:27 发布