自己编的黑白棋程序c++代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

ɾ³ý±¾¾ä»°£¬²¢½«Îļþºó׺¸ÄΪ.cpp#includeiostreamusingnamespacestd;intqi[8][8];voidprint_h(inth){cout(char)(h+65)¨c;for(intk=0;k8;k++){switch(qi[h][k]){case0:cout©à;break;case1:cout¡ò;break;case2:cout¡ñ;break;}}cout¨fendl;}voidprint(){cout£°£±£²£³£´£µ£¶£·endl;cout¨X¨h¨h¨h¨h¨h¨h¨h¨h¨[endl;for(intl=0;l8;l++)print_h(l);cout¨^¨k¨k¨k¨k¨k¨k¨k¨k¨aendl;}voidxiugai(inthang,intlie,intheng,intzong,intnum){for(inti=1;i=num;i++){hang+=heng;lie+=zong;qi[hang][lie]=3-qi[hang][lie];}}intpanduan(intcount,intshu,intse){intout;//out=0:²»¼ÌÐø;out=1:¼ÌÐø;out=2:²»¼ÌÐø²¢·µ»Ø³É¹¦;if(shu==0)out=0;elseif(shu==(3-se))out=1;elseif(count==1)out=0;elseout=2;returnout;}boolchuli(intse,inti,intj,boolleixing){boolctrl=false;intflag=1;inthang=i;intlie=j;intcount=0;while(hang0&&flag==1)//ÏòÉÏÅжÏ{hang--;count++;flag=panduan(count,qi[hang][lie],se);}if(flag==2)if(leixing){xiugai(i,j,-1,0,count-1);ctrl=true;}elsectrl=true;flag=1;count=0;hang=i;lie=j;while(hang7&&flag==1)//ÏòÏÂÅжÏ{hang++;count++;flag=panduan(count,qi[hang][lie],se);}if(flag==2)if(leixing){xiugai(i,j,1,0,count-1);ctrl=true;}elsectrl=true;flag=1;count=0;hang=i;lie=j;while(lie0&&flag==1)//Ïò×óÅжÏ{lie--;count++;flag=panduan(count,qi[hang][lie],se);}if(flag==2)if(leixing){xiugai(i,j,0,-1,count-1);ctrl=true;}elsectrl=true;flag=1;count=0;hang=i;lie=j;while(lie7&&flag==1)//ÏòÓÒÅжÏ{lie++;count++;flag=panduan(count,qi[hang][lie],se);}if(flag==2)if(leixing){xiugai(i,j,0,1,count-1);ctrl=true;}elsectrl=true;flag=1;count=0;hang=i;lie=j;while(hang0&&lie0&&flag==1)//Ïò×óÉÏÅжÏ{hang--;lie--;count++;flag=panduan(count,qi[hang][lie],se);}if(flag==2)if(leixing){xiugai(i,j,-1,-1,count-1);ctrl=true;}elsectrl=true;flag=1;count=0;hang=i;lie=j;while(hang7&&lie7&&flag==1)//ÏòÓÒÏÂÅжÏ{hang++;lie++;count++;flag=panduan(count,qi[hang][lie],se);}if(flag==2)if(leixing){xiugai(i,j,1,1,count-1);ctrl=true;}elsectrl=true;flag=1;count=0;hang=i;lie=j;while(hang0&&lie7&&flag==1)//ÏòÓÒÉÏÅжÏ{hang--;lie++;count++;flag=panduan(count,qi[hang][lie],se);}if(flag==2)if(leixing){xiugai(i,j,-1,1,count-1);ctrl=true;}elsectrl=true;flag=1;count=0;hang=i;lie=j;while(hang7&&lie0&&flag==1)//Ïò×óÏÂÅжÏ{hang++;lie--;count++;flag=panduan(count,qi[hang][lie],se);}if(flag==2)if(leixing){xiugai(i,j,1,-1,count-1);ctrl=true;}elsectrl=true;if(ctrl&&leixing)qi[i][j]=se;returnctrl;}intmain(){boolctrl=false,ctrl_all=false,ctrl_1=false,ctrl_2=false;intj=0;intn=1;intse=2;charh,l;intlie,hang;intcount_hei=0;intcount_bai=0;for(inti=0;i8;i++)for(j=0;j8;j++)qi[i][j]=0;qi[3][3]=1;qi[4][4]=1;qi[3][4]=2;qi[4][3]=2;while(n61){se=3-se;for(i=0;i8;i++){for(j=0;j8;j++){if(qi[i][j]==0){ctrl_1=(ctrl_1||chuli(1,i,j,false));if(ctrl_1&&ctrl_2)break;ctrl_2=(ctrl_2||chuli(2,i,j,false));if(ctrl_1&&ctrl_2)break;}}if(ctrl_1&&ctrl_2)break;}if(!(ctrl_1||ctrl_2))break;if((!ctrl_1)&&ctrl_2&&(se==1))continue;if((!ctrl_2)&&ctrl_1&&(se==2))continue;count_hei=0;count_bai=0;for(i=0;i8;i++)for(j=0;j8;j++){if(qi[i][j]==1)count_hei++;elseif(qi[i][j]==2)count_bai++;}print();coutºÚ·½count_hei:count_bai°×·½endl;if(se==1)coutºÚ·½ÏÂ×Óendl;elsecout°×·½ÏÂ×Óendl;while(!ctrl){cout;cinhl;coutendl;hang=h-65;lie=l-48;if(qi[hang][lie]!=0)ctrl=false;elsectrl=chuli(se,hang,lie,true);if(!ctrl)cout´Ë´¦²»ÄÜÂä×Ó!endl;}ctrl=false;ctrl_1=false;ctrl_2=false;n++;}count_hei=0;count_bai=0;for(i=0;i8;i++)for(j=0;j8;j++){if(qi[i][j]==1)count_hei++;elseif(qi[i][j]==2)count_bai++;}print();coutºÚ·½count_hei:count_bai°×·½endl;if(count_heicount_bai)coutºÚ·½Ê¤!endl;elseif(count_heicount_bai)cout°×·½Ê¤!endl;elsecout´òƽÁË!endl;cout°´ÈÎÒâ¼üÍ˳ö...endl;cini;return0;}

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功