bool MapIsFullyAccessible(bool[,]obstacleMap, int currentObstacleCount){bool[,] mapFlags = new bool[obstacleMap.GetLength(0),obstacleMap.GetLength(1)];//检查过的存个标记Queuequeue = new Queue();
queue.Enqueue (mapCenter);
mapFlags [mapCenter.x, mapCenter.y] = true;
int accessibleTileCount = 1;
while(queue.Count >0){
Coord tile = queue.Dequeue ();
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
int neighbourX = tile.x + x;
int neighbourY = tile.y + y;
if(x== 0 ||y==0 ){//保证是检测横竖4个值,而不检测四个角的四个值
if(neighbourX >= 0 && neighbourX < obstacleMap.GetLength(0)&& neighbourY >= 0 && neighbourY < obstacleMap.GetLength(1)){//保证所检测的位置不超出地图边界
if(!mapFlags[neighbourX,neighbourY] && !obstacleMap[neighbourX,neighbourY]){
mapFlags [neighbourX,neighbourY] = true;
queue.Enqueue (new Coord(neighbourX,neighbourY));
accessibleTileCount++;
}
}
}
}
}
}
int targetAccessibleTileCount = (int)mapSize.x * mapSize.y - currentObstacleCount;
return targetAccessibleTileCount == accessibleTileCount;
}