I have a 2d array created of size n that holds 1s and 0s representing closed and open spaces respectively.
Now I need to test the 2d array to see if it percolates and I'm not sure how to go about this.
I have the following code for creating the array and randomly assigning each spot to a 1 or 0.
int** grid = new int*[boardSize];
for (int i = 0; i < boardSize; ++i) {
grid[i] = new int[boardSize];
}
for (int i = 0; i < boardSize; i++) {
for (int j = 0; j < boardSize; j++) {
if (i == 0) {
grid[i][j] = 1;
}
else if (i == boardSize - 1) {
grid[i][j] = 1;
}
else if (j == 0) {
grid[i][j] = 1;
}
else if (j == boardSize - 1) {
grid[i][j] = 1;
}
else
grid[i][j] = random(delta);
}
}
grid[0][enter] = 0;
grid[boardSize - 1][exit] = 0;
This will create an array with closed borders (1s) and put 2 random entry/exit points (0s) on the top and bottom. Only part I'm missing is to test for percolation.
Any help is appreciated, thanks!