Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Program {
- public static void main(String[] args) {
- Percolation percolation = new Percolation(5, 5);
- Random randomGen = new Random();
- while(!percolation.connected(0, 5*5-1)) {
- int openedNode = randomGen.nextInt(5*5);
- percolation.grid[openedNode] = openedNode;
- int row = openedNode / 5;
- int column = openedNode % 5;
- if (row < 5 && row > 0) {
- percolation.union(openedNode, openedNode - 5);
- percolation.union(openedNode, openedNode + 5);
- } else if (row == 0) {
- percolation.union(openedNode, openedNode + 5);
- }
- }
- }
- }
- public class Percolation {
- public int size;
- public int times;
- int grid[];
- int sizes[];
- public Percolation(int size, int times){
- this.size = size;
- this.times = times;
- this.grid = new int[size*size];
- this.sizes = new int[size*size];
- initGrid();
- }
- public boolean connected(int nodeA, int nodeB) {
- return true;
- }
- public void union(int nodeA, int nodeB) {
- }
- private int root(int node) {
- while(node != grid[node]) {
- node = grid[node];
- }
- return node;
- }
- private void initGrid()
- {
- for (int i = 0; i < size; i++) {
- grid[i] = 00; //00 for vacant
- sizes[i] = 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement