资源描述:
《五子棋程序设计.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include#includeusingnamespacestd;constcharoutstr[11][4]={"┌","┬","┐","├","┼","┤","└","┴","┘","○","●"};intcom[15][15],luozi[15][15];intc,d;voidjushi()//这是判断落子重要性的函数{intx,y,i,m,n,lianzi1=0,lianzi2=0,life=0;memset(com,0,sizeof(com));for(x=0;x<=14;x++
2、)for(y=0;y<=14;y++){if(luozi[x][y]==0){for(m=-1;m<=1;m++)for(n=-1;n<=1;n++){if(m!=0
3、
4、n!=0){for(i=1;i<=4;i++){if(x+i*m>=0&&x+i*m<=14&&y+i*n>=0&&y+i*n<=14&&luozi[x+i*m][y+i*n]==1){lianzi1++;}elseif(luozi[x+i*m][y+i*n]==0){life++;break;}else{break;}}for(i=-1;i>=-4;i--){
5、if(x+i*m>=0&&x+i*m<=14&&y+i*n>=0&&y+i*n<=14&&luozi[x+i*m][y+i*n]==1){lianzi1++;}elseif(luozi[x+i*m][y+i*n]==0){life++;break;}else{break;}}if(lianzi1==1){com[x][y]+=1;}elseif(lianzi1==2){if(life==1){com[x][y]+=5;}elseif(life==2){com[x][y]+=10;}}elseif(lianzi1==3){if(l
6、ife==1){com[x][y]+=20;}elseif(life==2){com[x][y]+=100;}}elseif(lianzi1==4){com[x][y]+=500;}life=0;for(i=1;i<=4;i++){if(x+i*m>=0&&x+i*m<=14&&y+i*n>=0&&y+i*n<=14&&luozi[x+i*m][y+i*n]==2){lianzi2++;}elseif(luozi[x+i*m][y+i*n]==0){life++;break;}else{break;}}for(i=-1;i>=-
7、4;i--){if(x+i*m>=0&&x+i*m<=14&&y+i*n>=0&&y+i*n<=14&&luozi[x+i*m][y+i*n]==2){lianzi2++;}elseif(luozi[x+i*m][y+i*n]==0){life++;break;}else{break;}}if(lianzi2==1){com[x][y]+=2;}elseif(lianzi2==2){if(life==1){com[x][y]+=8;}elseif(life==2){com[x][y]+=30;}}elseif(lianzi2==
8、3){if(life==1){com[x][y]+=50;}elseif(life==2){com[x][y]+=200;}}elseif(lianzi2==4){com[x][y]+=1000;}lianzi1=0;lianzi2=0;life=0;}}}}}voidcomputer(inta[15][15])//这是电脑落子的函数{inti,j,max=0;jushi();for(i=0;i<=14;i++)for(j=0;j<=14;j++){if(com[i][j]>max){max=com[i][j];c=i;d=j;
9、}}a[c][d]=10;luozi[c][d]=2;}intpanduan(intx,inty,intsum)//判断胜负的函数{intm,n,i,lianzi=0;for(m=-1;m<=1;m++)for(n=-1;n<=1;n++){if(m!=0
10、
11、n!=0){for(i=1;i<=4;i++){if(x+i*m>=0&&x+i*m<=14&&y+i*n>=0&&y+i*n<=14&&luozi[x+i*m][y+i*n]==sum){lianzi++;}else{break;}}for(i=-1;i>=-4;i--)
12、{if(x+i*m>=0&&x+i*m<=14&&y+i*n>=0&&y+i*n<=14&&luozi[x+i*m][y+i*n]==sum){lianzi++;}else{break;}}if(lianzi>=4){return1;}else{lianzi=0