int main()
{
int i,j;
int qipan[20][20];
int qizi=-1;
int qizicount=1;
int tj,ti;
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
qipan[i][j]=2;
}
}
while(1)
{
printf("请输入棋子位置如2,2\n");
scanf("%d,%d",&i,&j);
if(i<1||i>20||j<1||j>20)
{
printf("棋子超出棋盘位置,请重新输入");
continue;
}
if((qipan[i-1][j-1]!=2))
{
printf("此位置已有棋子请重新输入");
fflush(stdin);
continue;
}
qizi=(qizi+1)%2;
qipan[i-1][j-1]=qizi;
for(i=0;i<20;i++)
{
if(i==0)
{
for(j=0;j<20;j++)
{
if(j==0)
{
if(qipan[i][j]==2)
printf("┌ ");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
else if(j>0&&j<19)
{
if(qipan[i][j]==2)
printf("┬ ");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
else if(j==19)
{
if(qipan[i][j]==2)
printf("┐");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
}
printf("\n");
}
else if(i>0&&i<19)
{
for(j=0;j<20;j++)
{
if(j==0)
{
if(qipan[i][j]==2)
printf("├ ");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
else if(j>0&&j<19)
{
if(qipan[i][j]==2)
printf("┼ ");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
else if(j==19)
{
if(qipan[i][j]==2)
printf("┤");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
}
printf("\n");
}
else if(i==19)
{
for(j=0;j<20;j++)
{
if(j==0)
{
if(qipan[i][j]==2)
printf("└ ");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
else if(j>0&&j<19)
{
if(qipan[i][j]==2)
printf("┴ ");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
else if(j==19)
{
if(qipan[i][j]==2)
printf("┘");
else if(qipan[i][j]==0)
printf("●");
else if(qipan[i][j]==1)
printf("○");
}
}
printf("\n");
}
}
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
if(qipan[i][j]!=2)
{
ti=i;tj=j;
for(tj=j+1;qipan[ti][tj]!=2&&tj<19;tj++){
if(qipan[ti][tj]==qipan[ti][tj-1])
qizicount++;
else break;
if(qizicount==5)
break;}
}
if(qizicount==5)
{
if(qipan[ti][tj]==0)
printf("白棋赢了");
else if(qipan[ti][tj]==1)
printf("黑棋赢了");
}
else qizicount=1;
if (qizicount==5)
break;
}
if (qizicount==5)
break;
}
for(j=0;j<20;j++)
{
for(i=0;i<20;i++)
{
if(qipan[i][j]!=2)
{
tj=j;
for(ti=i;qipan[ti+1][tj]==qipan[ti][tj]&&tj<19;ti++){
qizicount++;
if(qizicount==5)
break;}
}
if(qizicount==5)
{
if(qipan[ti][tj]==0)
printf("白棋赢了");
else if(qipan[ti][tj]==1)
printf("黑棋赢了");
}
else qizicount=1;
if(qizicount==5)
break;
}
if(qizicount==5)
break;
}
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
if(qipan[i][j]!=2)
for(tj=j,ti=i;qipan[ti][tj]!=2&&tj<19;tj--,ti--){
if(qipan[ti][tj]==qipan[ti-1][tj-1])
qizicount++;
else break;
if(qizicount==5)
break;}
}
if(qizicount==5)
{
if(qipan[ti][tj]==0)
printf("白棋赢了");
else if(qipan[ti][tj]==1)
printf("黑棋赢了");
}
else qizicount=1;
if(qizicount==5)
break;
}
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
if(qipan[i][j]!=2)
for(tj=j,ti=i;qipan[ti][tj]!=2&&tj<19;tj++,ti--){
if(qipan[ti][tj]==qipan[ti-1][tj+1])
qizicount++;
else break;
if(qizicount==5)
break;}
}
if(qizicount==5)
{
if(qipan[ti][tj]==0)
printf("白棋赢了");
else if(qipan[ti][tj]==1)
printf("黑棋赢了");
}
else qizicount=1;
if(qizicount==5)
break;
}
if(qizicount==5)
{
break;
}
}
return 0;
}
萌新上路代码不完善请多指教;
|