int count = 0;
for(int x = 1; x < 79; x++)
{
for(int y = 1; y < 21; y++)
{
char surroundingCells[] = {arr[x-1][y-1], arr[x][y-1], arr[x-1][y], arr[x+1][y+1], arr[x+1][y-1], arr[x-1][y+1], arr[x][y+1], arr[x+1][y]};
for(int z = 0; z < 8; z++)
{
if((surroundingCells[z] == 'x' || surroundingCells[z] == 'd') && arr[x][y] == 'x')
count++;
else if((surroundingCells[z] == ' ' || surroundingCells[z] == 'l') && arr[x][y] == ' ')
count++;
}
if(arr[x][y] == 'x' && (count != 2 || count != 3))
arr[x][y] = 'd';
else if(arr[x][y] == ' ' && count == 3)
arr[x][y] = 'l';
count = 0;
}
}
当我在运行此代码后打印数组时,所有有 x 的地方都有一个“d”,但不应该发生某些情况允许保留一个“x”。有人能看到我的逻辑错误吗?