求教大神c语言扫雷。。。谁能帮我改对么
#include<stdio.h>#include<time.h>
#include<stdlib.h>
int map[9][9] = {0};
int result[9][9] = {0};
int mine[10][2];
int Check(int i)
{
int j;
for(j=0;j<i;j++)
if(mine[j][0] == mine[i][0] && mine[j][1] == mine[i][0]) return 0;
return 1;
}
int MineNum(int x,int y)
{
int sum = 0;
int i,j;
if(x-1>=0 && x+1<=8 && y-1>=0 && y+1<=8)
{
for(i=x-1;i<=x+1;i++)
for(j=y-1;j<=y+1;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
if(x==0 && y==0) return (map[0][1]+map[1][0]+map[1][1])/9;
if(x==0 && y==8) return (map[0][7]+map[1][7]+map[1][8])/9;
if(x==8 && y==0) return (map[7][0]+map[7][1]+map[8][1])/9;
if(x==8 && y==8) return (map[7][7]+map[7][8]+map[8][7])/9;
if(x==0)
{
for(i=x;i<=x+1;i++)
for(j=y-1;j<=y+1;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
if(x==8)
{
for(i=x-1;i<=x;i++)
for(j=y-1;j<=y+1;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
if(y==0)
{
for(i=x-1;i<=x+1;i++)
for(j=y;j<=y+1;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
if(y==8)
{
for(i=x-1;i<=x+1;i++)
for(j=y-1;j<=y;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
}
void main()
{
int i,j,x,y;
srand((int)time(0));
for(i=0;i<10;i++)
{
do{
mine[i][0] = rand()%9;
mine[i][1] = rand()%9;
}while(Check(i));
printf("%d\t%d\n",mine[i][0],mine[i][1]);
}
for(i=0;i<10;i++) map[mine[i][0]][mine[i][1]] = 9;
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
if(map[i][j] == 9) result[i][j] = 9;
else result[i][j] = MineNum(i,j);
printf("%d ",result[i][j]);
}
printf("\n");
}
}