public static int[, ,] SmudgeArray3D(this int[, ,] intArea, double dblChance) { int[, ,] intNew = new int[intArea.GetLength(0), intArea.GetLength(1), intArea.GetLength(2)]; for (int x = 0; x < intArea.GetLength(0); x++) { for (int y = 0; y < intArea.GetLength(1); y++) { for (int z = 0; z < intArea.GetLength(2); z++) { if (RNG.NextDouble() <= dblChance) { int intNewX, intNewY, intNewZ; do { intNewX = RNG.Next(-1, 2); intNewY = RNG.Next(-1, 2); intNewZ = RNG.Next(-1, 2); } while (!intArea.IsValidPositionInArray3D(x + intNewX, y + intNewY, z + intNewZ) || Math.Abs(intNewX) + Math.Abs(intNewY) + Math.Abs(intNewZ) > 1); intNew[x, y, z] = intArea[x + intNewX, y + intNewY, z + intNewZ]; } else { intNew[x, y, z] = intArea[x, y, z]; } } } } return(intNew); }