Today, while organizing my documents, I found some C language programs that I wrote in the past. Now I want to share them with everyone. Program 1: Black and White Chess Program. It was a small game that first appeared on Mac, commonly known as Apple Chess. Did you play it when you were young? Let's debug and play with it. Debugging environment: GCC, TC. You should know if you have experience with C language. The code is as follows (only providing the AI part): Full address www.lidaren.com/code/WBchess.c.txt
int cal(char z)
{
int *p=0;
int num=0,i,j;
for(i=0;i<=7;i++)
{
for(j=0;j<=7;j++)
{
if(s[i][j]==z)
{
num++;
p=(int *)realloc(p,num*sizeof(int));
p[num-1]=i*10+j;
}
}
}
for(i=0;i<num;i++)
{
int x=p[i]/10,y=p[i]%10;
if(s[x+1][y]==z1&&(x+1)<=7)
{
i=2;
while(i+x<=7)
{
if(s[x+i][y]==z2)
{
can[0]=1;
break;
}
i++;
}
}
if(s[x-1][y]==z1&&(x-1)>=0)
{
i=2;
while(x-i>=0)
{
if(s[x-i][y]==z2)
{
can[1]=1;
break;
}
i++;
}
}
if(s[x][y+1]==z1&&(y+1)<=7)
{
i=2;
while(i+y<=7)
{
if(s[x][y+i]==z2)
{
can[2]=1;
break;
}
i++;
}
}
if(s[x][y-1]==z1&&(y-1)>=0)
{
i=2;
while(y-i>=0)
{
if(s[x][y-i]==z2)
{
can[3]=1;
break;
}
i++;
}
}
if(s[x-1][y+1]==z1&&(x-1)*(y+1)>=0)
{
i=2;
while(x-i>=0&&y+i<=7)
{
if(s[x-i][y+i]==z2)
{
can[4]=1;
break;
}
i++;
}
}
if(s[x+1][y-1]==z1&&(y-1)>=0)
{
i=2;
while(i+x<=7&&y-i>=0)
{
if(s[x+i][y-i]==z2)
{
can[5]=1;
break;
}
i++;
}
}
if(s[x-1][y-1]==z1&&(x-1)*(y-1)>=0)
{
i=2;
while(x-i>=0&&y-i>=0)
{
if(s[x-i][y-i]==z2)
{
can[6]=1;
break;
}
i++;
}
}
if(s[x+1][y+1]==z1)
{
i=2;
while(i+x<=7&&i+y<=7)
{
if(s[x+i][y+i]==z2)
{
can[7]=1;
break;
}
i++;
}
}
}
free(p);
}
Please note that the code provided above is only for the AI part.