#include<iostream> #include<string> #include<string.h> using namespace std; string cc[12] ={
""}; int aa[12][12]; int a[8] = {
1,1,1,0,0,-1,-1,-1}; int b[8] = {
-1,0,1,1,-1,0,1,-1}; int lg(int u); int mo(char c1,char c2,int u); int main() {
int n = 0; cin>>n; int pp = 0; for(int nn = 0;nn<n;++nn) {
if(pp++) {
cout<<endl; } for(int i = 1;i<=8;++i) cin>>cc[i]; int u = 1; char c; cin>>c; if(c == 'B') u = -1; string s; while(cin>>s && s[0]!='Q') {
if(s[0] == 'L') {
int f = lg(u); if(!f) {
u=u*(-1); cout<<"No legal move."<<endl; } else{
int de = 0; for(int i = 1;i<=8;++i) for(int j = 0;j<8;++j) if(aa[i][j] == 1) {
if(de++) {
cout<<' '; } cout<<'('<<i<<','<<j+1<<')'; } cout<<endl; } for(int lp = 0;lp<12;++lp) memset(aa[lp],0,sizeof(aa[lp])); } if(s[0] == 'M') {
if(mo(s[1],s[2],u)) {
int wc = 0; int bc = 0; for(int i = 1;i<=8;++i) {
for(int j = 0;j<8;++j) {
if(cc[i][j] == 'W') ++wc; if(cc[i][j] == 'B') ++bc; } } cout<<"Black - "; if(bc/10 < 1) cout<<' '; cout<<bc<<' '; cout<<"White - "; if(wc/10 < 1) cout<<' '; cout<<wc<<endl; }; u = u*(-1); } } for(int i = 1;i<=8;++i) cout<<cc[i]<<endl; } } int lg(int u) {
char e; char v; e = u==1?'W':'B'; v = u==1?'B':'W'; for(int i = 1;i<=8;++i) {
for(int j = 0;j<8;++j) {
if(cc[i][j] == e) {
for(int x = 0;x<8;++x) {
if(i+a[x]>=1 && i+a[x]<=8 && j+b[x]>=0 && j+b[x] <=7) {
if(cc[i+a[x]][j+b[x]] == v) {
int ax = i+a[x]; int ay = j+b[x]; while((ax>=1 && ax<=8 && ay>=0 && ay<=7) && cc[ax][ay] == v) {
ax+=a[x]; ay+=b[x]; } if((ax>=1 && ax<=8 && ay>=0 && ay<=7) && cc[ax][ay] == '-') aa[ax][ay] = 1; } } } } } } int fag = 0; for(int i = 1;i<=8;++i) for(int j = 0;j<8;++j) if(aa[i][j] == 1) fag = 1; if(fag == 0) return 0; return 1; } int mo(char c1,char c2,int u) {
int ae = c1-'0'; int as = c2-'0'; char e; char v; e = u==1?'W':'B'; v = u==1?'B':'W'; cc[ae][as-1] = e; for(int x = 0;x<8;++x) {
int cn = 0; if(ae+a[x]>=1 && ae+a[x]<=8 && as-1+b[x]>=0 && as-1+b[x] <=7) {
if(cc[ae+a[x]][as-1+b[x]] == v) {
int ax = ae+a[x]; int ay = as-1+b[x]; ++cn; while((ax>=1 && ax<=8 && ay>=0 && ay<=7) && cc[ax][ay] == v) {
ax+=a[x]; ay+=b[x]; ++cn; } if((ax>=1 && ax<=8 && ay>=0 && ay<=7) && cc[ax][ay] == e) {
for(int i =1;i<cn;++i) cc[ae+i*a[x]][as-1+i*b[x]] = e; } } } } return 1; }
讯享网

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/21127.html