public ArtifactData getCandidateAsync(String arg) throws Exception {
    reporter.trace("coordinate %s", arg);
    if (isUrl(arg))
      try {
        ArtifactData data = putAsync(new URI(arg));
        data.local = true;
        return data;
      } catch (Exception e) {
        reporter.trace("hmm, not a valid url %s, will try the server", arg);
      }

    Coordinate c = new Coordinate(arg);

    if (c.isSha()) {
      ArtifactData r = get(c.getSha());
      if (r != null) return r;
    }

    Revision revision = library.getRevisionByCoordinate(c);
    if (revision == null) return null;

    reporter.trace("revision %s", Hex.toHexString(revision._id));

    ArtifactData ad = get(revision._id);
    if (ad != null) {
      reporter.trace("found in cache");
      return ad;
    }

    URI url = revision.urls.iterator().next();
    ArtifactData artifactData = putAsync(url);
    artifactData.coordinate = c;
    return artifactData;
  }
Beispiel #2
0
 /**
  * Returns a hash value for this envelope. This value need not remain consistent between different
  * implementations of the same class.
  */
 @Override
 public int hashCode() {
   // Algorithm from Effective Java by Joshua Bloch [Jon Aquino]
   int result = super.hashCode();
   result = 37 * result + Coordinate.hashCode(minz);
   result = 37 * result + Coordinate.hashCode(maxz);
   int code = result ^ (int) serialVersionUID;
   return code;
 }
Beispiel #3
0
  /** @param - start is the starting coordinate */
  @Override
  public HashSet<Coordinate> getMoves(Coordinate start) {
    HashSet<Coordinate> moves = new HashSet<Coordinate>();
    int x = start.getXCoordinate();
    int y = start.getYCoordinate();
    // left diagonal
    moves.add(new Coordinate(x - 1, y - 1));
    // right diagonal
    moves.add(new Coordinate(x + 1, y - 1));

    super.movesOnBoard(moves);
    return moves;
  }
  public void findEdge(List dirEdgeList) {
    /**
     * Check all forward DirectedEdges only. This is still general, because each edge has a forward
     * DirectedEdge.
     */
    for (Iterator i = dirEdgeList.iterator(); i.hasNext(); ) {
      DirectedEdge de = (DirectedEdge) i.next();
      if (!de.isForward()) continue;
      checkForRightmostCoordinate(de);
    }

    /**
     * If the rightmost point is a node, we need to identify which of the incident edges is
     * rightmost.
     */
    Assert.isTrue(
        minIndex != 0 || minCoord.equals(minDe.getCoordinate()),
        "inconsistency in rightmost processing");
    if (minIndex == 0) {
      findRightmostEdgeAtNode();
    } else {
      findRightmostEdgeAtVertex();
    }
    /** now check that the extreme side is the R side. If not, use the sym instead. */
    orientedDe = minDe;
    int rightmostSide = getRightmostSide(minDe, minIndex);
    if (rightmostSide == Position.LEFT) {
      orientedDe = minDe.getSym();
    }
  }
Beispiel #5
0
 /**
  * Checks to see if moves are valid for the size of the board
  *
  * @param moves - set of moves
  * @return Set of moves with all the out of bounds moves removed
  */
 public HashSet<Coordinate> movesOnBoard(HashSet<Coordinate> moves) {
   // Hashset contains all the moves
   HashSet<Coordinate> allMoves = new HashSet<Coordinate>();
   for (Coordinate c : moves) {
     if (c.getXCoordinate() < 0
         || c.getXCoordinate() >= this.x
         || c.getYCoordinate() < 0
         || c.getYCoordinate() >= this.y) {
       allMoves.add(c);
     }
   }
   // remove the moves that are invalid (off the board)
   for (Coordinate c : allMoves) {
     moves.remove(c);
   }
   return moves;
 }
Beispiel #6
0
  /**
   * Get all valid diagonal moves
   *
   * @param start - starting coordinate
   * @return possible valid diagonal moves
   */
  public HashSet<Coordinate> diagonalMoves(Coordinate start) {
    HashSet<Coordinate> moves = new HashSet<Coordinate>();
    int x = start.getXCoordinate();
    int y = start.getYCoordinate();

    // get lower right
    while (x < this.x && y < this.y) {
      moves.add(new Coordinate(x, y));
      x++;
      y++;
    }
    x = start.getXCoordinate();
    y = start.getYCoordinate();
    // get upper left
    while (x >= 0 && y >= 0) {
      moves.add(new Coordinate(x, y));
      x--;
      y--;
    }
    x = start.getXCoordinate();
    y = start.getYCoordinate();

    // get lower left
    while (x >= 0 && y < this.y) {
      moves.add(new Coordinate(x, y));
      x--;
      y++;
    }
    x = start.getXCoordinate();
    y = start.getYCoordinate();
    // get lower right
    while (x < this.x && y >= 0) {
      moves.add(new Coordinate(x, y));
      x++;
      y--;
    }
    // remove current location
    moves.remove(start);

    return moves;
  }
Beispiel #7
0
  /**
   * Get all vertical and horizontal moves
   *
   * @param starting - starting coordinate
   * @return all valid vertical and horizontal moves
   */
  public HashSet<Coordinate> VHMoves(Coordinate start) {
    HashSet<Coordinate> moves = new HashSet<Coordinate>();
    int x = start.getXCoordinate();
    int y = start.getYCoordinate();
    // get north
    while (y >= 0) {
      moves.add(new Coordinate(start.getXCoordinate(), y));
      y--;
    }
    x = start.getXCoordinate();
    y = start.getYCoordinate();
    // get south
    while (y < this.y) {
      moves.add(new Coordinate(start.getXCoordinate(), y));
      y++;
    }
    x = start.getXCoordinate();
    y = start.getYCoordinate();
    // get east
    while (x < this.x) {
      moves.add(new Coordinate(x, start.getYCoordinate()));
      x++;
    }
    x = start.getXCoordinate();
    y = start.getYCoordinate();
    // get west
    while (x >= 0) {
      moves.add(new Coordinate(x, start.getYCoordinate()));
      x--;
    }
    moves.remove(start); // remove current location

    return moves;
  }
  public String ucsSolver() {
    long start_time, end_time;
    start_time = System.currentTimeMillis();
    System.out.println("Uniform");
    char[][] copyBoard;
    State start_state = new State(this.board.board, "", keeper);
    qu.push(start_state);
    visited.add(this.board.board);
    int count = 0;

    while (!qu.isEmpty()) {
      int index = getMinPathIndex(qu);
      State current_state = qu.get(index); /* TODO add sort Function to get the smallest */
      copyBoard = current_state.board;
      so = current_state.path;
      int x = current_state.cor.x;
      int y = current_state.cor.y;

      qu.remove(index); /* TODO add remove index function */
      number_of_nodes++;

      for (int i = 0; i < 4; i++) {
        // number_of_nodes++;
        int dx = dirs.getDirections()[i].direction.x;
        int dy = dirs.getDirections()[i].direction.y;
        char[][] tempBoard = cloneBoard(copyBoard);

        if (tempBoard[x + dx][y + dy] == '$' || tempBoard[x + dx][y + dy] == '*') {
          if (push(x, y, dx, dy, tempBoard)) {
            if (isVisited(visited, tempBoard)) previous_nodes++;
            else {
              if (isSolved(tempBoard)) {
                fringe_nodes = qu.size();
                explored_list = visited.size();
                end_time = System.currentTimeMillis();
                taken_time = end_time - start_time;
                return so + dirs.getDirections()[i].moveType[1];
              }
              Coordinate new_keeper = new Coordinate(x + dx, y + dy);
              new_keeper.setCost(current_state.cor.getCost() + 2);
              visited.add(tempBoard);
              qu.add(new State(tempBoard, so + dirs.getDirections()[i].moveType[1], new_keeper));
            }
          }
        } else if (move(x, y, dx, dy, tempBoard)) {
          if (isVisited(visited, tempBoard)) previous_nodes++;
          else {
            if (isSolved(tempBoard)) {
              fringe_nodes = qu.size();
              explored_list = visited.size();
              end_time = System.currentTimeMillis();
              taken_time = end_time - start_time;
              return so + dirs.getDirections()[i].moveType[0];
            }
            Coordinate new_keeper = new Coordinate(x + dx, y + dy);
            new_keeper.setCost(current_state.cor.getCost() + 1);
            visited.add(tempBoard);
            qu.add(new State(tempBoard, so + dirs.getDirections()[i].moveType[0], new_keeper));
          }
        }
      }
      count++;
    }
    return "No Solution";
  }
Beispiel #9
0
 /**
  * Add node to samples.
  *
  * @param node node to add to samples
  * @param resultSet set of resulting nodes
  * @return set of n nodes
  */
 protected SortedVector addNode(Node node, SortedVector resultSet) {
   resultSet.add(new NodeDistance(node, point.distance(node)));
   while (resultSet.size() > n) resultSet.remove(resultSet.size() - 1);
   return resultSet;
 }
Beispiel #10
0
  Table(BeerCell controller) {
    this.controller = controller;

    // Work out where all of the stacks should go
    // 5% margins
    marginLeft = (int) (width * .05);
    marginRight = (int) (width * .05);
    marginTop = (int) (height * .05);
    marginBottom = (int) (height * .05);

    // Other Spacings
    hSpacingPlay = (int) (width * .03);
    hSpacingCell = (int) (width * .01);
    hSpacingHome = (int) (width * .01);
    vSpacing = (int) (height * .05);
    // cSpacing = (int) (width * .10);

    // The rest of the space can be used for stacks
    stackWidth = ((width - (marginLeft + marginRight + (hSpacingPlay * 7))) / 8);
    cardHeight = (int) (stackWidth * 1.33);

    //		// Create the stacks, calculating their base screen position as we go along.
    //		int playStackTopMargin = marginTop + cardHeight + vSpacing;
    //		for (int i=0; i < play.length; i++) {
    //			PlayStack theStack = new PlayStack((marginLeft + ((stackWidth + hSpacingPlay) * i)),
    // playStackTopMargin, stackWidth, (height - playStackTopMargin - marginBottom));
    //			theStack.setCardHeight(cardHeight);
    //			play[i] = theStack;
    //
    //		}
    //		for (int i=0; i < cell.length; i++) {
    //			cell[i] = new CellStack((marginLeft + ((stackWidth + hSpacingCell) * i)), marginTop,
    // stackWidth, cardHeight);
    //		}
    //		for (int i=0; i < home.length; i++) {
    //			Coordinate startingPoint = new Coordinate(width - (marginRight + ((stackWidth +
    // hSpacingHome) * home.length)), marginTop);
    //			home[i] = new HomeStack(startingPoint.getX() + ((stackWidth + hSpacingHome) * i),
    // startingPoint.getY(), stackWidth, cardHeight);
    //		}

    // Create the stacks, calculating their base screen position as we go along.
    int playStackTopMargin = marginTop + cardHeight + vSpacing;
    for (int i = 0; i < stacks.length; i++) {
      if (i < PLAYSTACKLENGTH) { // Play stacks
        PlayStack theStack =
            new PlayStack(
                (marginLeft + ((stackWidth + hSpacingPlay) * i)),
                playStackTopMargin,
                stackWidth,
                (height - playStackTopMargin - marginBottom));
        theStack.setCardHeight(cardHeight);
        stacks[i] = theStack;
      } else if ((i >= PLAYSTACKLENGTH) && (i < PLAYSTACKLENGTH + CELLSTACKLENGTH)) { // Cell stacks
        stacks[i] =
            new CellStack(
                (marginLeft + ((stackWidth + hSpacingCell) * (i - PLAYSTACKLENGTH))),
                marginTop,
                stackWidth,
                cardHeight);
      } else { // Home Stacks
        Coordinate startingPoint =
            new Coordinate(width - (marginRight + ((stackWidth + hSpacingHome) * 4)), marginTop);
        stacks[i] =
            new HomeStack(
                startingPoint.getX()
                    + ((stackWidth + hSpacingHome) * (i - PLAYSTACKLENGTH - CELLSTACKLENGTH)),
                startingPoint.getY(),
                stackWidth,
                cardHeight);
      }
    }

    populatePlayArea(new Deck(stackWidth, cardHeight));

    // Start the cursor off at play[0]
    cursor = new Cursor(stacks[cursorLocation]);
    cursor.setOffset(stackWidth / 2, cardHeight / 2);

    timerStrip =
        new TimerStrip(this, 0, this.getHeight() - marginBottom, this.getWidth(), this.getHeight());
  }
 /**
  * Tests whether a given point is in an array of points. Uses a value-based test.
  *
  * @param pt a {@link Coordinate} for the test point
  * @param pts an array of {@link Coordinate}s to test
  * @return <code>true</code> if the point is in the array
  * @deprecated
  */
 public static boolean isInList(Coordinate pt, Coordinate[] pts) {
   for (int i = 0; i < pts.length; i++) {
     if (pt.equals(pts[i])) return true;
   }
   return false;
 }