有段C程序,编译不出来,无法交作业
#include <stdio.h>
typedef char chess[10];
typedef int temparr[10];
chess arr;
temparr brr;
int number,sye,c3,n2,c2,n1,c1;
char ch;
void inarrdata(chess a)
{
a[1]='1';
a[2]='2';
a[3]='3';
a[4]='4';
a[5]='5';
a[6]='6';
a[7]='7';
a[8]='8';
a[9]='9';
}
void display(chess a)
{
printf("\n");
printf("\n");
printf(" %c|%c|%c\n",a[1],a[2],a[3]);
printf(" ------------------------\n");
printf(" %c|%c|%c\n",a[4],a[5],a[6]);
printf(" -------------------------\n");
printf(" %c|%c|%c\n",a[7],a[8],a[9]);
printf("\n");
printf("\n");
}
int arrfull()
{
int i;
int arrf=0;
for (i=1; i<=9;i++)
if(i== arr[i]-48)arrf=1;
return arrf;
}
void cn(int line)
{
switch(line)
{
case0:c3=c3+1; break;
case1:n2=n2+1; break;
case2:c2=c2+1; break;
case3:n1=n1+1; break;
case4:c1=c1+1; break;
}
}
int linenum(char a, char c, char b)
{
int ln =5;
if((a=='X')&&(b=='X')&&(c=='X'))
ln=0;
if(((a=='O')&&(b=='O')&&(c!='O'))
||((a=='O')&&(b!='O'))&&(c=='O'))
||((a!='O')&&(b=='O')&&(c=='O')))
ln=1;
if(((a=='X')&&(b=='X')&&(c!='X'))
||((a=='X')&&(b!='X')&&(c=='X'))
||((a!='X')&&(b=='X')&&(c=='X')))
ln=2;
if(((a=='O')&&(b!='O')&&(c!='O'))
||((a!='O')&&(b=='O')&&(c!='O'))
||((a!='O')&&(b!='O')&&(c=='O')))
ln=3;
if(((a=='X')&&(b!='X')&&(c!='X')
||((a!='X')&&(b=='X')&&(c!='X')
||((a!='X')&&(b!='X')&&(c=='X')))
ln=4;
return ln;
}
int maxbrr(int * br)
{
int temp, i, mb;
temp=-888;
for (i=2;i<=9;i++)
{
if(temp<=br[i])
{
temp=br[i];
mb=i;
}
}
return mb ;
}
void mansetp()
{
int j;
display(arr);
if(arrfull())
{
printf("Please input step:");
scanf("%d",&j);
while((j<1)||(j>9)||(j!=arr[j]-48))
{
printf("input step err, please again.");
scanf("%d",&j);
}
arr[j]='O';
}
}
void computerstep()
{
int i;
if(arrfull())
{
for(i=1;i<=9;i++)
{
if(i==arr[i]-48)
{
c3=0;n2=0;c2=0;
n1=0;c1=0;
arr[i]='X';
number=linenum(arr[1],arr[2],arr[3]); cn(number);
number=linenum(arr[4],arr[5],arr[6]); cn(number);
number=linenum(arr[7],arr[8],arr[9]); cn(number);
number=linenum(arr[1],arr[4],arr[7]); cn(number);
number=linenum(arr[2],arr[5],arr[8]); cn(number);
number=linenum(arr[3],arr[6],arr[9]); cn(number);
number=linenum(arr[1],arr[5],arr[9]); cn(number);
number=linenum(arr[3],arr[5],arr[7]); cn(number);
brr[i]=(128*c3-63*n2+31*c2-15*n1+7*n1);
arr[i]=i+48;
}
else brr[i]=-999;
}
arr[maxbrr(brr)]='X';
c3=0;n2=0;c2=0;n2=0;n1=0;c1=0;
number=linenum(arr[1],arr[2],arr[3]); cn(number);
number=linenum(arr[4],arr[5],arr[6]); cn(number);
number=linenum(arr[7],arr[8],arr[9]); cn(number);
number=linenum(arr[1],arr[4],arr[7]); cn(number);
number=linenum(arr[2],arr[5],arr[8]); cn(number);
number=linenum(arr[3],arr[6],arr[9]); cn(number);
number=linenum(arr[1],arr[5],arr[9]); cn(number);
number=linenum(arr[3],arr[5],arr[9]); cn(number);
if(c3!=0)
{
display(arr);
printf("\n");
printf("The computer win!!");
exit(0);
suc = 0;
}
else suc=0;
}
main()
{
inarrdata(arr);
display(arr);
suc=1;
printf(" Do you first step?(y\n)");
scanf("%c",&ch);
if((ch=='y')||(ch=='Y'))
{
while (suc)
{
manstep();
computerstep();
}
display(arr);
}
else
{
while(suc)
{ computerstep();
if(suc)
manstep();
}
}
printf("\n drawn!!!\n");
}