public class AshCloud { public AshCloud (int n, double f) { double[][] grid = new double[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { grid[i][j] = 0.0; } } grid[n/2][n/2] = 1.0; } public double [][] runSimulation (char dir , int steps ) { double[][] grid = new double[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { grid[i][j] = 0.0; } } grid[n/2][n/2] = 1.0; if (dir == "N") { for (int i = 0; i < steps; i++) { for (int j = 0; j < n; j++) { grid[i][j] = grid[i][j] * (1-f) + grid[i+1][j] * f; } } } if (dir == "S") { for (int i = 0; i < steps; i++) { for (int j = 0; j < n; j++) { grid[i][j] = grid[i][j] * (1-f) + grid[i-1][j] * f; } } } if (dir == "E") { for (int i = 0; i < steps; i++) { for (int j = 0; j < n; j++) { grid[i][j] = grid[i][j] * (1-f) + grid[i][j+1] * f; } } } if (dir == "W") { for (int i = 0; i < steps; i++) { for (int j = 0; j < n; j++) { grid[i][j] = grid[i][j] * (1-f) + grid[i][j-1] * f; } } } } }