Ejemplo n.º 1
0
  public void replacePointMarkersOnLine() {
    int width = getWidth();
    int height = getHeight();
    for (int yi = 0; yi < height; yi++) {
      for (int xi = 0; xi < width; xi++) {
        char c = get(xi, yi);
        Cell cell = new Cell(xi, yi);
        if (StringUtils.isOneOf(c, pointMarkers) && isStarOnLine(cell)) {

          boolean isOnHorizontalLine = false;
          if (StringUtils.isOneOf(get(cell.getEast()), horizontalLines)) isOnHorizontalLine = true;
          if (StringUtils.isOneOf(get(cell.getWest()), horizontalLines)) isOnHorizontalLine = true;

          boolean isOnVerticalLine = false;
          if (StringUtils.isOneOf(get(cell.getNorth()), verticalLines)) isOnVerticalLine = true;
          if (StringUtils.isOneOf(get(cell.getSouth()), verticalLines)) isOnVerticalLine = true;

          if (isOnHorizontalLine && isOnVerticalLine) {
            set(xi, yi, '+');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with +");
          } else if (isOnHorizontalLine) {
            set(xi, yi, '-');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with -");
          } else if (isOnVerticalLine) {
            set(xi, yi, '|');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with |");
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
 public void removeColorCodes() {
   for (CellColorPair o : findColorCodes()) {
     Cell cell = o.cell;
     set(cell, ' ');
     cell = cell.getEast();
     set(cell, ' ');
     cell = cell.getEast();
     set(cell, ' ');
     cell = cell.getEast();
     set(cell, ' ');
   }
 }
Ejemplo n.º 3
0
 public void replaceBullets() {
   int width = getWidth();
   int height = getHeight();
   for (int yi = 0; yi < height; yi++) {
     for (int xi = 0; xi < width; xi++) {
       Cell cell = new Cell(xi, yi);
       if (isBullet(cell)) {
         set(cell, ' ');
         set(cell.getEast(), '\u2022');
       }
     }
   }
 }
Ejemplo n.º 4
0
  private CellSet seedFillOld(Cell seed, char newChar) {
    CellSet cellsFilled = new CellSet();
    char oldChar = get(seed);

    if (oldChar == newChar) return cellsFilled;
    if (isOutOfBounds(seed)) return cellsFilled;

    Stack<Cell> stack = new Stack<Cell>();

    stack.push(seed);

    while (!stack.isEmpty()) {
      Cell cell = stack.pop();

      set(cell, newChar);
      cellsFilled.add(cell);

      Cell nCell = cell.getNorth();
      Cell sCell = cell.getSouth();
      Cell eCell = cell.getEast();
      Cell wCell = cell.getWest();

      if (get(nCell) == oldChar) stack.push(nCell);
      if (get(sCell) == oldChar) stack.push(sCell);
      if (get(eCell) == oldChar) stack.push(eCell);
      if (get(wCell) == oldChar) stack.push(wCell);
    }

    return cellsFilled;
  }
Ejemplo n.º 5
0
 public void removeArrowheads() {
   int width = getWidth();
   int height = getHeight();
   for (int yi = 0; yi < height; yi++) {
     for (int xi = 0; xi < width; xi++) {
       Cell cell = new Cell(xi, yi);
       if (isArrowhead(cell)) set(cell, ' ');
     }
   }
 }
Ejemplo n.º 6
0
 /**
  * Replaces letters or numbers that are on horizontal or vertical lines, with the appropriate
  * character that will make the line continuous (| for vertical and - for horizontal lines)
  */
 public void replaceTypeOnLine() {
   int width = getWidth();
   int height = getHeight();
   for (int yi = 0; yi < height; yi++) {
     for (int xi = 0; xi < width; xi++) {
       char c = get(xi, yi);
       if (Character.isLetterOrDigit(c)) {
         boolean isOnHorizontalLine = isOnHorizontalLine(xi, yi);
         boolean isOnVerticalLine = isOnVerticalLine(xi, yi);
         if (isOnHorizontalLine && isOnVerticalLine) {
           set(xi, yi, '+');
           if (DEBUG) System.out.println("replaced type on line '" + c + "' with +");
         } else if (isOnHorizontalLine) {
           set(xi, yi, '-');
           if (DEBUG) System.out.println("replaced type on line '" + c + "' with -");
         } else if (isOnVerticalLine) {
           set(xi, yi, '|');
           if (DEBUG) System.out.println("replaced type on line '" + c + "' with |");
         }
       }
     }
   }
 }
Ejemplo n.º 7
0
  public void removeBoundaries() {
    ArrayList<Cell> toBeRemoved = new ArrayList<Cell>();

    int width = getWidth();
    int height = getHeight();
    for (int yi = 0; yi < height; yi++) {
      for (int xi = 0; xi < width; xi++) {
        Cell cell = new Cell(xi, yi);
        if (isBoundary(cell)) toBeRemoved.add(cell);
      }
    }

    // remove in two stages, because decision of
    // isBoundary depends on contants of surrounding
    // cells
    for (Object aToBeRemoved : toBeRemoved) {
      Cell cell = (Cell) aToBeRemoved;
      set(cell, ' ');
    }
  }
Ejemplo n.º 8
0
  /**
   * Locates and returns the '*' boundaries that we would encounter if we did a flood-fill at <code>
   * seed</code>.
   */
  public CellSet findBoundariesExpandingFrom(Cell seed) {
    CellSet boundaries = new CellSet();
    char oldChar = get(seed);

    if (isOutOfBounds(seed)) return boundaries;

    char newChar = 1; // TODO: kludge

    Stack<Cell> stack = new Stack<Cell>();

    stack.push(seed);

    while (!stack.isEmpty()) {
      Cell cell = stack.pop();

      set(cell, newChar);

      Cell nCell = cell.getNorth();
      Cell sCell = cell.getSouth();
      Cell eCell = cell.getEast();
      Cell wCell = cell.getWest();

      if (get(nCell) == oldChar) stack.push(nCell);
      else if (get(nCell) == '*') boundaries.add(nCell);

      if (get(sCell) == oldChar) stack.push(sCell);
      else if (get(sCell) == '*') boundaries.add(sCell);

      if (get(eCell) == oldChar) stack.push(eCell);
      else if (get(eCell) == '*') boundaries.add(eCell);

      if (get(wCell) == oldChar) stack.push(wCell);
      else if (get(wCell) == '*') boundaries.add(wCell);
    }

    return boundaries;
  }
Ejemplo n.º 9
0
 /** Fills all the cells in <code>cells</code> with <code>c</code> */
 public void fillCellsWith(Iterable<Cell> cells, char c) {
   for (Cell cell : cells) {
     set(cell.x, cell.y, c);
   }
 }
Ejemplo n.º 10
0
 public void copyCellsTo(CellSet cells, TextGrid grid) {
   for (Cell cell : cells) {
     grid.set(cell, this.get(cell));
   }
 }
Ejemplo n.º 11
0
 public void set(Cell cell, char c) {
   set(cell.x, cell.y, c);
 }