Exemplo n.º 1
0
  public void genMaze() {
    Node current =
        nodes[(int) (Math.random() * (MazeSize - 1))][(int) (Math.random() * (MazeSize - 1))];

    while (visited.size() < MazeSize * MazeSize) {

      if (!visited.contains(current)) {
        current.setVisited(true);
        visited.add(current);
        nodeStack.push(current);

        while (!nodeStack.isEmpty()) {
          traverse(nodes);
        }
      }
    }
  }
Exemplo n.º 2
0
  public Node[][] traverse(Node[][] nodes) {

    if (!nodeStack.empty()) {

      Node current = nodeStack.pop();
      current = initiateNeighbors(current);
      current.setVisited(true);
      visited.add(current);

      double randProb = Math.random();

      if (randProb <= 0.2d) {
        current.setBlocked(true);
      }

      ArrayList<Node> neighbors = current.getNeighbors();
      for (Node nbr : neighbors) {
        if (!visited.contains(nbr)) {
          nodeStack.push(nbr);
        }
      }
    }
    return nodes;
  }