人人对战:
#include<iostream>
using namespace std;
void wz()
{
cout<<"下面开始五子棋比赛,一号选手用方块符号,二号用心型符号:"<<endl<<endl;
for(int i=3;i>0;i--)
{
cout<<i<<" ";
}
cout<<"开始-----------"<<endl<<endl;
}
int hs()
{
int x,y,i=0,j=1;
char d[80][80];
//初始化---
for(x=0;x<25;x+=3)
{
for(y=0;y<80;y+=3)
{
d[x][y]='+';
}
}
//第一行数字--
for(x=0;x<10;x++)
cout<<x<<" ";
for(x=10;x<27;x++)
cout<<x<<" ";
cout<<endl;
//输出棋盘--
for(x=0;x<25;x+=3)
{
cout<<j<<" ";j++;
for(y=0;y<76;y+=3)
{
cout<<d[x][y]<<" ";
}
cout<<endl;
}
while(1)
{
int a,b;
if(i%2==0)
cout<<"由玩家一下棋:"<<endl;
else
cout<<"由玩家二下棋:"<<endl;
cin>>a>>b;
if(i%2==1)
{
if(d[(a-1)*3][(b-1)*3]=='+')
d[(a-1)*3][(b-1)*3]=3;
else
{
cout<<"-----------------------------不能覆盖棋子:"<<endl;
continue;
}
}
else
{
if(d[(a-1)*3][(b-1)*3]=='+')
d[(a-1)*3][(b-1)*3]=1;
else
{
cout<<"-----------------------------不能覆盖棋子:"<<endl;
continue;
}
}
i++;
j=1;
//第一行数字---
for(x=0;x<10;x++)
cout<<x<<" ";
for(x=10;x<27;x++)
cout<<x<<" ";
cout<<endl;
for(x=0;x<25;x+=3)
{
cout<<j<<" ";j++;
for(y=0;y<76;y+=3)
{
cout<<d[x][y]<<" ";
}
cout<<endl;
}
//判断是否是五个
if(//横着
d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1&&d[(a-1)*3][(b+2)*3]==1&&d[(a-1)*3][(b+3)*3]==1
||d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1&&d[(a-1)*3][(b+2)*3]==1
||d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1
||d[(a-1)*3][(b-4)*3]==1&&d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1
||d[(a-1)*3][(b-5)*3]==1&&d[(a-1)*3][(b-4)*3]==1&&d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//从左上到右下
||d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1&&d[(a+2)*3][(b+2)*3]==1&&d[(a+3)*3][(b+3)*3]==1
||d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1&&d[(a+2)*3][(b+2)*3]==1
||d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1
||d[(a-4)*3][(b-4)*3]==1&&d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1
||d[(a-5)*3][(b-5)*3]==1&&d[(a-4)*3][(b-4)*3]==1&&d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//从右上到左下
||d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[a-3][b+1]==1&&d[a-4][b+2]==1&&d[a-5][b+3]==1
||d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[(a-3)*3][(b+1)*3]==1&&d[(a-4)*3][(b+2)*3]==1
||d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[(a-3)*3][(b+1)*3]==1
||d[(a+2)*3][(b-4)*3]==1&&d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1
||d[(a+3)*3][(b-5)*3]==1&&d[(a+2)*3][(b-4)*3]==1&&d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//竖着
||d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1&&d[(a+2)*3][(b-1)*3]==1&&d[(a+3)*3][(b-1)*3]==1
||d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1&&d[(a+2)*3][(b-1)*3]==1
||d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1
||d[(a-4)*3][(b-1)*3]==1&&d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1
||d[(a-5)*3][(b-1)*3]==1&&d[(a-4)*3][(b-1)*3]==1&&d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1
)
{
cout<<endl<<"玩家一获胜"<<endl;break;
}
if(//横着
d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3&&d[(a-1)*3][(b+2)*3]==3&&d[(a-1)*3][(b+3)*3]==3
||d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3&&d[(a-1)*3][(b+2)*3]==3
||d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3
||d[(a-1)*3][(b-4)*3]==3&&d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3
||d[(a-1)*3][(b-5)*3]==3&&d[(a-1)*3][(b-4)*3]==3&&d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//从左上到右下
||d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3&&d[(a+2)*3][(b+2)*3]==3&&d[(a+3)*3][(b+3)*3]==3
||d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3&&d[(a+2)*3][(b+2)*3]==3
||d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3
||d[(a-4)*3][(b-4)*3]==3&&d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3
||d[(a-5)*3][(b-5)*3]==3&&d[(a-4)*3][(b-4)*3]==3&&d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//从右上到左下
||d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[a-3][b+1]==3&&d[a-4][b+2]==3&&d[a-5][b+3]==3
||d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[(a-3)*3][(b+1)*3]==3&&d[(a-4)*3][(b+2)*3]==3
||d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[(a-3)*3][(b+1)*3]==3
||d[(a+2)*3][(b-4)*3]==3&&d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3
||d[(a+3)*3][(b-5)*3]==3&&d[(a+2)*3][(b-4)*3]==3&&d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//竖着
||d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3&&d[(a+2)*3][(b-1)*3]==3&&d[(a+3)*3][(b-1)*3]==3
||d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3&&d[(a+2)*3][(b-1)*3]==3
||d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3
||d[(a-4)*3][(b-1)*3]==3&&d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3
||d[(a-5)*3][(b-1)*3]==3&&d[(a-4)*3][(b-1)*3]==3&&d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3
)
{
cout<<endl<<"玩家二获胜"<<endl;break;
}
}
return 0;
}
int main()
{
char a;
wz();
hs();
while(1)
{
cout<<"按P重新开始:";
cin>>a;
if(a=='p')
hs();
else
break;
}
return 0;
}
人机对战暂时没想出来,有知道的希望指教一下!!感激----