Esempio n. 1
0
  void storeXml(ParseIndexContext ctx, Path xml) throws IOException {
    Files.createFile(xml);
    PrintWriter p = new PrintWriter(Files.newBufferedWriter(xml, utf8));
    p.print("<?xml version='1.1' encoding='" + NotesRetriever.utf8.name() + "'?><snotes>");

    ctx.list.sort(Comparator.comparing(o1 -> o1.number));
    for (NoteListItem i : ctx.list) {
      p.print("\n<n");
      p.print(" n='" + i.number + "'");
      if (i.mark != null) p.print(" m='" + i.mark + "'");
      p.print(" a='" + i.apparea + "'");
      p.print(" l='" + i.asklangu + "'");
      p.print(" d='" + DateTimeFormatter.ISO_LOCAL_DATE.format(i.date) + "'");
      p.print(" c='" + i.category + "'");
      p.print(" p='" + i.priority + "'");
      if (i.objid != null) p.print(" o='" + i.objid + "'");
      p.print(">" + StringEscapeUtils.escapeXml11(i.title) + "</n>");
    }
    p.flush();
    for (Pair<String, String> a : ctx.lareas) {
      p.print("\n<area rcode='" + a.getKey() + "' value='" + a.getValue() + "'/>");
    }
    p.flush();
    //		p.print("\n<!-- [Statistics]");
    //		if (dsd==0 && dod==0) {
    //			p.print("\tNotes collected: " + q + ", no duplicates found");
    //		} else {
    //			p.print("\nUnique notes collected: " + q);
    //			p.print("\nDuplicate notes with the same date: " + dsd);
    //			p.print("\nDuplocate notes with the other date: " + dod);
    //		}
    //		p.println("\t-->");
    p.print("\n</snotes>");
    p.close();
  }
 ArrayList<Pair<Model, String>> filter() {
   ArrayList<Pair<Model, String>> tempList = new ArrayList<Pair<Model, String>>();
   for (Pair<Model, String> ob : data) if (check(ob.getKey())) tempList.add(ob);
   data = tempList;
   ShowResults();
   return tempList;
 }
Esempio n. 3
0
 public static Pair<Integer, Suspect[]> clearSuspect(Pair<Integer, Suspect[]> items) {
   ArrayList<Suspect> spcts = new ArrayList<>();
   for (Suspect item : items.getValue()) {
     if (item.value != 0) {
       spcts.add(item);
     }
   }
   return new Pair<Integer, Suspect[]>(items.getKey(), spcts.toArray(new Suspect[spcts.size()]));
 }
Esempio n. 4
0
 public void addAnchors(ComponentView componentView) {
   Pair<CoordinatePair, CoordinatePair> pairedCoordinates = addAnchorLines(componentView);
   // Left Anchor
   Anchor anchor1 = new Anchor(componentView.getParentComponent(), pairedCoordinates.getKey());
   // Right Anchor
   Anchor anchor2 = new Anchor(componentView.getParentComponent(), pairedCoordinates.getValue());
   setInteractions(anchor1);
   setInteractions(anchor2);
   componentView.getChildren().addAll(anchor1, anchor2);
 }
  /**
   * Method called to handle the situation where a user selects one of his/her pieces to move.
   *
   * @param piece Piece selected on the board
   */
  public void handlePickPiece(Piece piece) {
    // set currentPiece and locate its position
    currentPiece = piece;
    char file = piece.getFile();
    int rank = piece.getRank();

    // low-light its space
    light(gui.getSpaceAt(file, rank), false);
    ArrayList<Pair<Character, Integer>> moveList = master.moveList(piece);

    // highlight and enable legal moves
    for (javafx.util.Pair<Character, Integer> move : moveList) {
      int currRank = move.getValue();
      char currFile = move.getKey();
      light(gui.getSpaceAt(currFile, currRank), true);
    }
  }
Esempio n. 6
0
  public RSR(GoState[][] b, int s) {
    checkList = new ArrayList<>();

    board = b;
    boardSize = s;

    for (int i = 0; i < boardSize; i++)
      for (int j = 0; j < boardSize; j++)
        if (board[i][j] != GoState.Free) {
          checkList.clear();
          player = board[i][j];

          if (!isAlive(i, j, RDir.None)) {
            for (Pair<Integer, Integer> p : checkList)
              board[p.getKey()][p.getValue()] = GoState.Free;
          }
        }
  }
  private static double getDistance(char a, char b) {
    double dist = 0;
    Pair<Double, Double> cord_a = getCoordinate(a);
    Pair<Double, Double> cord_b = getCoordinate(b);

    dist += Math.abs(cord_a.getKey() - cord_b.getKey());
    dist += Math.abs(cord_a.getValue() - cord_b.getValue());

    return dist;
  }
 public void status() {
   final Pair<String, String> status = administration.status();
   showMessage();
   message.setText("Interval: " + status.getKey() + " next timeout: " + status.getValue());
 }
Esempio n. 9
0
 @Override
 public int compare(Pair<Integer, Double> o1, Pair<Integer, Double> o2) {
   return o1.getValue() < o2.getValue() ? -1 : o1.getValue() == o2.getValue() ? 0 : 1;
 }
Esempio n. 10
0
  public Set<Move> getAllowedMoves() {
    // If there is already a winn
    if (gipfBoardState.players.winner() != null) {
      return Collections.emptySet();
    }

    // Create a set of incomplete moves containing the starting positions and directions for the
    // current piece
    Set<Move> potentialMoves = getPotentialStartMoves(getCurrentPiece());

    // If the current piece is a GIPF piece, the player is also allowed to place normal pieces.
    if (getCurrentPiece().getPieceType() == GIPF)
      potentialMoves.addAll(
          getPotentialStartMoves(Piece.of(NORMAL, getCurrentPiece().getPieceColor())));

    // These moves are marked as complete so a temporary game won't ask for user input.
    potentialMoves.stream().forEach(m -> m.isCompleteMove = true);

    Set<Move> potentialMovesIncludingLineSegmentRemoval = new HashSet<>();
    for (Move potentialMove : potentialMoves) {
      try {
        Map<Position, Piece> temporaryPieceMap = new HashMap<>(getGipfBoardState().getPieceMap());
        temporaryPieceMap.put(potentialMove.startPos, potentialMove.addedPiece);
        movePiecesTowards(
            temporaryPieceMap, potentialMove.getStartingPosition(), potentialMove.getDirection());

        Set<List<Pair<PieceColor, Line.Segment>>> RLineOrderingsSet =
            getRemovableLineOrderingsSetFromGipfBoard(
                temporaryPieceMap, getCurrentPiece().getPieceColor());
        if (RLineOrderingsSet.size() > 0) {
          for (List<Pair<PieceColor, Line.Segment>> RLineOrdering : RLineOrderingsSet) {
            Set<Position> piecesToWhite = new HashSet<>();
            Set<Position> piecesToBlack = new HashSet<>();
            Set<Position> piecesRemoved = new HashSet<>();

            for (Pair<PieceColor, Line.Segment> RLine : RLineOrdering) {
              Line.Segment removedSegment = RLine.getValue();

              // The color of the player who removed the line
              PieceColor colorRemoved = RLine.getKey();

              // Determine per segment to whom the pieces are given. Pieces can only be given to the
              // player
              // who removed the line, or deleted from the game.
              Set<Position> occupiedPositions =
                  removedSegment.getOccupiedPositions(temporaryPieceMap);
              Set<Position> piecesFromSegmentBackToReserve =
                  occupiedPositions
                      .stream()
                      .filter(
                          position ->
                              temporaryPieceMap.get(position).getPieceColor() == colorRemoved)
                      .collect(toSet());
              Set<Position> piecesFromSegmentRemoved =
                  occupiedPositions
                      .stream()
                      .filter(position -> !piecesFromSegmentBackToReserve.contains(position))
                      .collect(toSet());

              if (colorRemoved == WHITE) piecesToWhite.addAll(piecesFromSegmentBackToReserve);
              if (colorRemoved == BLACK) piecesToBlack.addAll(piecesFromSegmentBackToReserve);
              piecesRemoved.addAll(piecesFromSegmentRemoved);
            }

            // And finally add the move
            // the constructor will define this as a complete move, because all the parameters have
            // a value.
            potentialMovesIncludingLineSegmentRemoval.add(
                new Move(
                    potentialMove.addedPiece,
                    potentialMove.startPos,
                    potentialMove.direction,
                    piecesToWhite,
                    piecesToBlack,
                    piecesRemoved));
          }
        } else {
          // If no line segments can be removed, just add the original move
          potentialMovesIncludingLineSegmentRemoval.add(potentialMove);
        }
      } catch (InvalidMoveException e) {
        // We don't consider this move if it is invalid
      }
    }

    return potentialMovesIncludingLineSegmentRemoval;
  }