扫雷当点到空白处的迭代算法
扫雷点到空白处后展开与空白处相邻的空白处:
int ComputeEmpty(int aMine[][12],int x,int y)
{
if(x < 1 || x > 10 || y < 1 || y > 10)
return -1;
cout<<"("<<x<<","<<y<<")\t";
aMine[x][y] = -2;
0 != aMine[x-1][y-1] ? -1 :ComputeEmpty(aMine,x - 1,y - 1);
0 != aMine[x-1][y] ? -1 :ComputeEmpty(aMine,x - 1,y);
0 != aMine[x-1][y+1] ? -1 :ComputeEmpty(aMine,x - 1,y + 1);
0 != aMine[x][y-1] ? -1 :ComputeEmpty(aMine,x,y - 1);
0 != aMine[x][y+1] ? -1 :ComputeEmpty(aMine,x,y + 1);
0 != aMine[x+1][y-1] ? -1 :ComputeEmpty(aMine,x + 1,y - 1);
0 != aMine[x+1][y] ? -1 :ComputeEmpty(aMine,x + 1,y);
0 != aMine[x+1][y+1] ? -1 :ComputeEmpty(aMine,x + 1,y + 1);
return 0;
}