Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class Program {
  4.  
  5. public static void main(String[] args) {
  6. Percolation percolation = new Percolation(5, 5);
  7. Random randomGen = new Random();
  8.  
  9. while(!percolation.connected(0, 5*5-1)) {
  10. int openedNode = randomGen.nextInt(5*5);
  11. percolation.grid[openedNode] = openedNode;
  12. int row = openedNode / 5;
  13. int column = openedNode % 5;
  14. if (row < 5 && row > 0) {
  15. percolation.union(openedNode, openedNode - 5);
  16. percolation.union(openedNode, openedNode + 5);
  17. } else if (row == 0) {
  18. percolation.union(openedNode, openedNode + 5);
  19. }
  20. }
  21. }
  22.  
  23. }
  24.  
  25.  
  26.  
  27. public class Percolation {
  28.  
  29. public int size;
  30. public int times;
  31.  
  32. int grid[];
  33. int sizes[];
  34.  
  35. public Percolation(int size, int times){
  36. this.size = size;
  37. this.times = times;
  38. this.grid = new int[size*size];
  39. this.sizes = new int[size*size];
  40. initGrid();
  41. }
  42.  
  43. public boolean connected(int nodeA, int nodeB) {
  44. return true;
  45. }
  46.  
  47. public void union(int nodeA, int nodeB) {
  48.  
  49. }
  50.  
  51. private int root(int node) {
  52. while(node != grid[node]) {
  53. node = grid[node];
  54. }
  55. return node;
  56. }
  57.  
  58. private void initGrid()
  59. {
  60. for (int i = 0; i < size; i++) {
  61. grid[i] = 00; //00 for vacant
  62. sizes[i] = 1;
  63. }
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement