Exemplo n.º 1
0
  public int toDOT(FileWriter fr, boolean redColored, int i) throws IOException {

    String red, format, val, blue;
    int me = i, aux;
    if (redColored) {
      red = "color=red, style=filled, ";
    } else {
      red = "";
    }
    if (value == Integer.MAX_VALUE || value == Integer.MIN_VALUE) {
      val = "";
      blue = "color=blue, style=filled, ";
    } else {
      val = "" + value;
      blue = "";
    }
    format = getDOTFormat();
    fr.append(me + " [" + red + blue + format + "label=\"" + pos.toString() + " " + val + "\"];\n");
    boolean redSon, selected = true;
    for (Node son : childs) {
      if (selected && son.value == value) {
        selected = false;
        redSon = true;
      } else {
        redSon = false;
      }
      aux = i + 1;
      i = son.toDOT(fr, redSon, ++i);
      fr.append(me + " -> " + aux + ";\n");
    }
    return i;
  }
Exemplo n.º 2
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.º 3
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;
  }
Exemplo n.º 4
0
 public Position nextMove(
     int maxLevel, long level, boolean prune, Integer parentVal, TimeInfo timeInfo) {
   if (timeInfo != null) {
     timeInfo.update();
   }
   if (maxLevel == level) {
     getHeuristicalValue();
     return pos;
   }
   Position nextPos = pos;
   setChilds();
   level++;
   for (Node child : childs) {
     if (prune && pruneBranch(parentVal)) {
       return null;
     }
     if (child.chooseMove(value)) {
       child.nextMove(maxLevel, level, prune, value, timeInfo);
       nextPos = child.pos;
       value = child.value;
     }
   }
   return nextPos;
 }
Exemplo n.º 5
0
  public Node initiateNeighbors(Node n) {

    ArrayList<Node> nbrs = new ArrayList<Node>();
    ArrayList<Node> temp = new ArrayList<Node>();

    if (n.getY() < Maze.MazeSize - 1) nbrs.add(nodes[n.getX()][n.getY() + 1]);

    if (n.getY() > 0) nbrs.add(nodes[n.getX()][n.getY() - 1]);

    if (n.getX() > 0) nbrs.add(nodes[n.getX() - 1][n.getY()]);

    if (n.getX() < Maze.MazeSize - 1) nbrs.add(nodes[n.getX() + 1][n.getY()]);

    n.setNeighbors(nbrs);

    return n;
  }