Example #1
0
  public void pawnPromotion(Point p) {

    if (b.get(p) instanceof Pawn && p.getY() == 8) {
      b.remove(p);
      b.put(p, new Queen(true));
    } else if (b.get(p) instanceof Pawn && p.getY() == 1) {
      b.remove(p);
      b.put(p, new Queen(false));
    }
  }
  /**
   * Writes a triangle in ASCII.
   *
   * @param writer The file we want to write in.
   * @param triangle The triangle to write.
   */
  private static void writeASCIITriangle(final BufferedWriter writer, final Triangle triangle) {
    try {
      // Write facet normal : to begin a triangle with writing its normal.
      String s1 = "\nfacet normal";

      s1 +=
          " "
              + triangle.getNormal().x
              + " "
              + triangle.getNormal().y
              + " "
              + triangle.getNormal().z;

      // Write outer loop : to begin to write the three points.
      writer.write(s1 + "\nouter loop");
      // Write the three points.
      for (final Point p : triangle.getPoints()) {
        writer.write("\nvertex" + " " + p.getX() + " " + p.getY() + " " + p.getZ());
      }

      // Write the end of the facet.
      writer.write("\nendloop\nendfacet");
    } catch (final java.io.IOException e) {
      e.printStackTrace();
    }
  }
Example #3
0
  public boolean checkIfPathIsClear(Point startPosition, Point endPosition) {
    boolean isPathClear = true;

    Point difference = new Point();
    difference.setLocation(
        Math.abs(endPosition.getX() - startPosition.getX()),
        Math.abs(endPosition.getY() - startPosition.getY()));

    if (difference.getX() > 0 && difference.getY() == 0) {
      int largerPlace =
          (int)
              (startPosition.getX() > endPosition.getX()
                  ? startPosition.getX()
                  : endPosition.getX());
      for (int j = (int) (largerPlace - (difference.getX() - 1)); j < largerPlace; j++) {
        if (b.containsKey(new Point(j, (int) startPosition.getY()))) {
          isPathClear = false;
        }
      }

    } else if ((int) difference.getY() > 0 && (int) difference.getX() == 0) {
      int largerPlace = 0;
      if (startPosition.getY() > endPosition.getY()) {
        largerPlace = (int) startPosition.getY();
      } else {
        largerPlace = (int) endPosition.getY();
      }
      for (int i = largerPlace - ((int) difference.getY() - 1); i < largerPlace; i++) {
        if (b.containsKey(new Point((int) startPosition.getX(), i))) {
          isPathClear = false;
        }
      }
    } else if (difference.getX() == difference.getY()) {
      int leftPoint =
          (int)
              (startPosition.getX() < endPosition.getX()
                  ? startPosition.getY()
                  : endPosition.getY());
      int rightPoint =
          (int)
              (startPosition.getX() > endPosition.getX()
                  ? startPosition.getY()
                  : endPosition.getY());
      int largerPlace =
          (int)
              (startPosition.getX() > endPosition.getX()
                  ? startPosition.getX()
                  : endPosition.getX());

      int slope = leftPoint - rightPoint;

      int y = slope > 0 ? leftPoint - 1 : leftPoint + 1;

      for (int j = (int) (largerPlace - (difference.getX() - 1)); j < largerPlace; j++) {
        if (b.containsKey(new Point(j, y))) {
          isPathClear = false;
        }
        y = slope > 0 ? y - 1 : y + 1;
      }
    }

    return isPathClear;
  }