private void adjustDateLineCrossingPoints() {
      ArrayList<LatLon> corners = new ArrayList<LatLon>(Arrays.asList(sw, se, nw, ne));
      if (!LatLon.locationsCrossDateLine(corners)) return;

      double lonSign = 0;
      for (LatLon corner : corners) {
        if (Math.abs(corner.getLongitude().degrees) != 180)
          lonSign = Math.signum(corner.getLongitude().degrees);
      }

      if (lonSign == 0) return;

      if (Math.abs(sw.getLongitude().degrees) == 180
          && Math.signum(sw.getLongitude().degrees) != lonSign)
        sw = new Position(sw.getLatitude(), sw.getLongitude().multiply(-1), sw.getElevation());
      if (Math.abs(se.getLongitude().degrees) == 180
          && Math.signum(se.getLongitude().degrees) != lonSign)
        se = new Position(se.getLatitude(), se.getLongitude().multiply(-1), se.getElevation());
      if (Math.abs(nw.getLongitude().degrees) == 180
          && Math.signum(nw.getLongitude().degrees) != lonSign)
        nw = new Position(nw.getLatitude(), nw.getLongitude().multiply(-1), nw.getElevation());
      if (Math.abs(ne.getLongitude().degrees) == 180
          && Math.signum(ne.getLongitude().degrees) != lonSign)
        ne = new Position(ne.getLatitude(), ne.getLongitude().multiply(-1), ne.getElevation());
    }
 private int wrapPositionForTabbedTextWithOptimization(
     @NotNull CharSequence text,
     int tabSize,
     int startLineOffset,
     int endLineOffset,
     int targetRangeEndOffset) {
   int width = 0;
   int symbolWidth;
   int result = Integer.MAX_VALUE;
   boolean wrapLine = false;
   for (int i = startLineOffset; i < Math.min(endLineOffset, targetRangeEndOffset); i++) {
     char c = text.charAt(i);
     switch (c) {
       case '\t':
         symbolWidth = tabSize - (width % tabSize);
         break;
       default:
         symbolWidth = 1;
     }
     if (width + symbolWidth + FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS
             >= mySettings.RIGHT_MARGIN
         && (Math.min(endLineOffset, targetRangeEndOffset) - i)
             >= FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS) {
       // Remember preferred position.
       result = i - 1;
     }
     if (width + symbolWidth >= mySettings.RIGHT_MARGIN) {
       wrapLine = true;
       break;
     }
     width += symbolWidth;
   }
   return wrapLine ? result : -1;
 }
Ejemplo n.º 3
0
  /*
   * We completed handling of a filtered block. Update false-positive estimate based
   * on the total number of transactions in the original block.
   *
   * count includes filtered transactions, transactions that were passed in and were relevant
   * and transactions that were false positives (i.e. includes all transactions in the block).
   */
  protected void trackFilteredTransactions(int count) {
    // Track non-false-positives in batch.  Each non-false-positive counts as
    // 0.0 towards the estimate.
    //
    // This is slightly off because we are applying false positive tracking before non-FP tracking,
    // which counts FP as if they came at the beginning of the block.  Assuming uniform FP
    // spread in a block, this will somewhat underestimate the FP rate (5% for 1000 tx block).
    double alphaDecay = Math.pow(1 - FP_ESTIMATOR_ALPHA, count);

    // new_rate = alpha_decay * new_rate
    falsePositiveRate = alphaDecay * falsePositiveRate;

    double betaDecay = Math.pow(1 - FP_ESTIMATOR_BETA, count);

    // trend = beta * (new_rate - old_rate) + beta_decay * trend
    falsePositiveTrend =
        FP_ESTIMATOR_BETA * count * (falsePositiveRate - previousFalsePositiveRate)
            + betaDecay * falsePositiveTrend;

    // new_rate += alpha_decay * trend
    falsePositiveRate += alphaDecay * falsePositiveTrend;

    // Stash new_rate in old_rate
    previousFalsePositiveRate = falsePositiveRate;
  }
Ejemplo n.º 4
0
 public Unit() {
   trm = (Math.random() * 10) - 5;
   prm = (Math.random() * 10) - 5;
   wtm = (Math.random() * 10) - 5;
   tkm = (Math.random() * 10) - 5;
   ped = (Math.random() * 5) + 5;
 }
Ejemplo n.º 5
0
 // Returns the distance between two planets, rounded up to the next highest
 // integer. This is the number of discrete time steps it takes to get
 // between the two planets.
 public int Distance(int sourcePlanet, int destinationPlanet) {
   Planet source = planets.get(sourcePlanet);
   Planet destination = planets.get(destinationPlanet);
   double dx = source.X() - destination.X();
   double dy = source.Y() - destination.Y();
   return (int) Math.ceil(Math.sqrt(dx * dx + dy * dy));
 }
Ejemplo n.º 6
0
 public double nextDouble() {
   int c = read();
   while (isSpaceChar(c)) c = read();
   int sgn = 1;
   if (c == '-') {
     sgn = -1;
     c = read();
   }
   double res = 0;
   while (!isSpaceChar(c) && c != '.') {
     if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt());
     if (c < '0' || c > '9') throw new InputMismatchException();
     res *= 10;
     res += c - '0';
     c = read();
   }
   if (c == '.') {
     c = read();
     double m = 1;
     while (!isSpaceChar(c)) {
       if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt());
       if (c < '0' || c > '9') throw new InputMismatchException();
       m /= 10;
       res += (c - '0') * m;
       c = read();
     }
   }
   return res * sgn;
 }
Ejemplo n.º 7
0
 /**
  * Given a tissue sample, move all unsatisfied agents to a vacant cell
  *
  * @param tissue a 2-D character array that has been initialized
  * @param threshold the percentage of like agents that must surround the agent to be satisfied
  */
 public static int moveAllUnsatisfied(char[][] tissue, int threshold) {
   ArrayList<Integer> list2 = new ArrayList<Integer>();
   int counter = 0;
   ArrayList<Integer> list1 = new ArrayList<Integer>();
   for (int i = 0; i < tissue.length; i++) {
     for (int x = 0; x < tissue[0].length; x++) {
       if (isSatisfied(tissue, i, x, threshold) == false) {
         list1.add(i);
         list2.add(x);
       }
     }
   }
   int num = list1.size();
   char temp;
   int count = 0;
   do {
     int rand = (int) (Math.random() * tissue.length);
     int random = (int) (Math.random() * tissue.length);
     if (tissue[rand][random] == ' ') {
       temp = tissue[rand][random];
       tissue[rand][random] = tissue[list1.get(counter)][list2.get(counter)];
       tissue[list1.get(counter)][list2.get(counter)] = temp;
       counter++;
       count++;
     }
   } while (counter != num);
   return count;
 }
Ejemplo n.º 8
0
  public int[] solve(String[] edgeStrings) {

    ArrayList<Integer> oddPoints = new ArrayList<Integer>();

    int min = Integer.MAX_VALUE;
    for (String s : edgeStrings) {
      StringTokenizer st = new StringTokenizer(s);
      int from = Integer.parseInt(st.nextToken());
      int to = Integer.parseInt(st.nextToken());
      edges.add(new Edge(from, to));

      min = Math.min(min, from);
      min = Math.min(min, to);
      oddPoint(oddPoints, from);
      oddPoint(oddPoints, to);
    }

    assert (oddPoints.size() < 3);

    if (oddPoints.size() > 0) {
      dfs(min(oddPoints));
      return toArray(circuit);
    } else {
      dfs(min);
      return toArray(circuit);
    }
  }
Ejemplo n.º 9
0
  public void paint(Graphics gg) {
    int faceSize = Math.min(getWidth() - 4, getHeight() - 4);
    if (face == null)
      face =
          new PADFaceMapped(
              Math.max(2, (getWidth() - faceSize) / 2),
              Math.max(2, (getHeight() - faceSize) / 2),
              faceSize);
    if (buffer == null) {
      im = this.createImage(getWidth(), getHeight());
      buffer = im.getGraphics();
    }
    super.paint(buffer);

    buffer.setColor(new Color(255, 255, 255, 0));
    buffer.fillRect(0, 0, im.getWidth(null), im.getHeight(null));

    face.setDimensions(
        Math.max(2, (getWidth() - faceSize) / 2),
        Math.max(2, (getHeight() - faceSize) / 2),
        faceSize);
    face.paint(buffer);

    // draw buffer to screen
    gg.drawImage(im, 0, 0, null, null);
  }
Ejemplo n.º 10
0
 public double distanciaEuclidiana(int x1, int x2, int y1, int y2) {
   double a, b, c;
   a = Math.pow(x2 - x1, 2);
   b = Math.pow(y2 - y1, 2);
   c = Math.sqrt(a + b);
   return (c);
 }
Ejemplo n.º 11
0
  private void renderBlackout(Graphics g, int x, int y, int radius) {
    if (radius > 320) return;

    int[] xp = new int[20];
    int[] yp = new int[20];
    for (int i = 0; i < 16; i++) {
      xp[i] = x + (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y + (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 240;
    xp[18] = 0;
    yp[18] = 240;
    xp[19] = 0;
    yp[19] = y;
    g.fillPolygon(xp, yp, xp.length);

    for (int i = 0; i < 16; i++) {
      xp[i] = x - (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y - (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 0;
    xp[18] = 0;
    yp[18] = 0;
    xp[19] = 0;
    yp[19] = y;

    g.fillPolygon(xp, yp, xp.length);
  }
Ejemplo n.º 12
0
  public static void main(String[] args) throws IOException {
    input.init(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int depth = input.nextInt();
    int n = (1 << (depth + 1));
    int[] as = new int[n];
    for (int i = 2; i < n; i++) as[i] = input.nextInt();
    int[] paths = new int[n];
    int max = 0;
    ArrayList<Integer>[] under = new ArrayList[n];
    for (int i = 0; i < n; i++) under[i] = new ArrayList<Integer>();
    for (int i = (1 << (depth)); i < n; i++) {
      int cur = i;
      while (cur > 1) {
        under[cur].add(i);
        paths[i] += as[cur];
        cur /= 2;
      }
      max = Math.max(max, paths[i]);
    }
    int res = 0;
    for (int i = 2; i < n; i++) {
      int cm = 0;
      for (int x : under[i]) cm = Math.max(cm, paths[x]);
      int diff = max - cm;
      res += diff;
      for (int x : under[i]) paths[x] += diff;
    }
    out.println(res);
    out.close();
  }
Ejemplo n.º 13
0
  // evaluate Fisher score of all indexes in current ^ featIndex
  private double evaluateFisher(HashSet<Integer> current, int featIndex) {
    ArrayList<Integer> d = new ArrayList<Integer>(current);
    d.add(featIndex);
    ArrayList<ArrayList<Integer>> vectors = new ArrayList<ArrayList<Integer>>();
    for (int i = 0; i < getA().get_classes().size(); i++) {
      ArrayList<ArrayList<Integer>> cl = getA().features.get(getA().get_classes().get(i));
      ArrayList<Integer> tmp = new ArrayList<Integer>();
      for (int j = 0; j < cl.size(); j++) {
        int sum = 0;
        for (int k = 0; k < d.size(); k++) sum += cl.get(j).get(d.get(k));
        if (sum == d.size()) tmp.add(1);
        else tmp.add(0);
      }
      vectors.add(tmp);
    }
    ArrayList<double[]> stats = new ArrayList<double[]>();
    int count = 0;
    double sum = 0.0;
    for (int i = 0; i < vectors.size(); i++) {
      double[] res = computeMeanVariance(vectors.get(i));
      sum += (vectors.get(i).size() * res[0]);
      count += vectors.get(i).size();
      stats.add(res);
    }
    sum = sum / count;

    double num = 0.0;
    double denom = 0.0;
    for (int i = 0; i < stats.size(); i++) {
      num += (vectors.get(i).size() * Math.pow(stats.get(i)[0] - sum, 2));
      denom += (vectors.get(i).size() * Math.pow(stats.get(i)[1], 2));
    }
    if (denom == 0.0) return 0;
    else return num / denom;
  }
Ejemplo n.º 14
0
 private String getPercentsTailHelper(BigDecimal percents) {
   return ((percents.doubleValue() - Math.floor(percents.doubleValue())) > 0)
       ? " целых "
           + Math.round((percents.doubleValue() - Math.floor(percents.doubleValue())) * 100)
           + " сотых"
       : "";
 }
Ejemplo n.º 15
0
 void go3(int x, int y, int v, int at) {
   if (at == -1) return;
   if (y < a[at] || x > b[at]) return;
   val[at] += (Math.min(b[at], y) - Math.max(a[at], x) + 1) * v;
   go3(x, y, v, left[at]);
   go3(x, y, v, right[at]);
 }
Ejemplo n.º 16
0
  public static void main(String[] args) {
    Locale[] locales = Locale.getAvailableLocales();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    Map map = new HashMap(locales.length);
    int conflicts = 0;

    for (int i = 0; i < locales.length; i++) {
      Locale loc = locales[i];
      int hc = loc.hashCode();
      min = Math.min(hc, min);
      max = Math.max(hc, max);
      Integer key = new Integer(hc);
      if (map.containsKey(key)) {
        conflicts++;
        System.out.println("conflict: " + (Locale) map.get(key) + ", " + loc);
      } else {
        map.put(key, loc);
      }
    }
    System.out.println(
        locales.length
            + " locales: conflicts="
            + conflicts
            + ", min="
            + min
            + ", max="
            + max
            + ", diff="
            + (max - min));
    if (conflicts >= (locales.length / 10)) {
      throw new RuntimeException(
          "too many conflicts: " + conflicts + " per " + locales.length + " locales");
    }
  }
  private boolean isNotSeparatorRoom(Room separatorRoom, Room joinerRoom) {
    if (separatorRoom == null) return false;

    if (separatorRoom.isRotatable() && separatorRoom != joinerRoom) {
      separatorRoom.rotateRightRotatedType();
      rotationMap.put(
          separatorRoom.getDistance() - Math.abs(separatorRoom.getRotation()), separatorRoom);
      return false;
    }

    if (separatorRoom.isRotatable()
        && separatorRoom == joinerRoom
        && separatorRoom.getExit() != null) {
      if (separatorRoom.getRotatedType() == RoomType.TYPE_7) {
        separatorRoom.rotateRightRotatedType();
      } else if (separatorRoom.getRotatedType() == RoomType.TYPE_8
          && separatorRoom.getEntrance() == Direction.LEFT) {
        separatorRoom.rotateLeftRotatedType();
      } else if (separatorRoom.getRotatedType() == RoomType.TYPE_8
          && separatorRoom.getEntrance() == Direction.RIGHT) {
        separatorRoom.rotateRightRotatedType();
      } else if (separatorRoom.getRotatedType() == RoomType.TYPE_9
          && separatorRoom.getEntrance() == Direction.TOP) {
        separatorRoom.rotateLeftRotatedType();
      } else if (separatorRoom.getRotatedType() == RoomType.TYPE_9
          && separatorRoom.getEntrance() == Direction.LEFT) {
        separatorRoom.rotateRightRotatedType();
      }
      rotationMap.put(
          separatorRoom.getDistance() - Math.abs(separatorRoom.getRotation()), separatorRoom);
      return false;
    }

    return true;
  }
Ejemplo n.º 18
0
  /**
   * The assignInstance method is used to assign the instances to the centroid which is closest to
   * them (By squared Euclidean distance
   */
  private static void assignInstance(double[][] centroids, double[][] instances, KMeansResult res) {
    // for all instances to update centroids
    for (int i = 0; i < instances.length; i++) {
      // assign each instance to its closest centroid (index starts from 0)
      int centerId = -1;

      // initially set the distance of two points to be as big as possible
      // (which in math is regarded as infinite)
      double minDistance = Double.MAX_VALUE;

      // loop over centroids
      for (int j = 0; j < centroids.length; j++) {
        double currDistance = 0;
        // dimension
        for (int k = 0; k < centroids[j].length; k++) {
          currDistance = currDistance + Math.pow(instances[i][k] - centroids[j][k], 2);
        }
        currDistance = Math.sqrt(currDistance);

        if (currDistance < minDistance) {
          // update new distance to min distance
          minDistance = currDistance;
          // update new centroid
          centerId = j;
        }
      }
      res.clusterAssignment[i] = centerId;
    }
  }
Ejemplo n.º 19
0
 public void mouseReleased(MouseEvent e) {
   left_mouse_pressed = false;
   double kvadrat = Math.sqrt(angleX * angleX + angleY * angleY);
   double tempx = angleX / kvadrat;
   double tempy = Math.sqrt(1 - tempx * tempx);
   if (angleY < 0) tempy = -tempy;
   Bullet b = new Bullet();
   boolean next = false;
   if (type_bullet1 == true && count_sphere > 0) {
     b = new Sphere();
     count_sphere--;
     next = true;
   }
   if (type_bullet2 == true && count_fireball > 0) {
     b = new FireBall();
     count_fireball--;
     next = true;
   }
   if (type_bullet3 == true && count_rocket > 0) {
     b = new Rocket();
     count_rocket--;
     next = true;
   }
   if (next == true) {
     b.bullet_x = player.getX() + 52 + 5 * Math.cos(angle); // + 50; //koef;
     b.bullet_y = player.getY() + 49 + 5 * Math.sin(angle); // player.getY() + 35; //25;
     b.current_direction_x = tempx;
     b.current_direction_y = tempy;
     bullet.addElement(b);
     allow_shoot = false;
   }
 }
Ejemplo n.º 20
0
 private void bonbakKokatu() {
   int b = 0;
   int alt;
   int zab;
   while (b < this.bonbaKop) {
     alt = (int) (Math.random() * this.altuera - 1);
     zab = (int) (Math.random() * this.zabalera - 1);
     if (!(alt + 1 == this.hasAlt || alt - 1 == this.hasAlt)
         && !(zab + 1 == this.hasZab
             || zab - 1 == this.hasZab)) { // If honen baldintza luzea da, hasieran click
       // egin dugun posizioaren alboan bonbak ez kokatzeko
       if (laukiak[alt][zab] == null) {
         laukiak[alt][zab] = new Bonba();
         bonbenKoor.add(alt);
         bonbenKoor.add(zab);
         b++;
       } else if (laukiak[alt][zab].banderaDu()) {
         laukiak[alt][zab].eskuinClickEgin(alt, zab);
         laukiak[alt][zab] = new Bonba();
         laukiak[alt][zab].eskuinClickEgin(alt, zab);
         bonbenKoor.add(alt);
         bonbenKoor.add(zab);
         b++;
       }
     }
   }
   System.out.println("Bonbak kokatu dira");
 }
Ejemplo n.º 21
0
 public void printLoop(int n, float x[], float y[]) {
   // Need to swap the y component
   Polygon P = new Polygon();
   for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i]));
   poly_draw.add(P);
   poly_draw_color.add(curColor);
 }
Ejemplo n.º 22
0
 /**
  * Gets the maximum extent of this envelope across all three dimensions.
  *
  * @return the maximum extent of this envelope
  */
 @Override
 public double maxExtent() {
   if (isNull()) {
     return 0.0;
   }
   return Math.max(getWidth(), Math.max(getHeight(), getDepth()));
 }
Ejemplo n.º 23
0
  public static int gainKillExperience(Thing h, Thing t) {
    int hlevel = h.getLevel();
    int tlevel = t.getLevel();

    int killcount = 0;
    if (h.isHero()) {
      killcount = incKillCount(t);
      if (killcount == 1) {
        Score.scoreFirstKill(t);
      }
    }

    int base = t.getStat("XPValue");
    double xp = base;
    xp = xp * Math.pow(experienceDecay, killcount);
    xp = xp * Math.pow(experienceLevelMultiplier, tlevel - 1);

    // decrease xp gain for killing lower level monsters
    if (hlevel > tlevel) xp = xp / (hlevel - tlevel);

    int gain = (int) xp;

    Hero.gainExperience(gain);
    return gain;
  }
Ejemplo n.º 24
0
  /** Returns angle in degrees from specified origin to specified destination. */
  public static int getAngle(Point origin, Point destination) // origin != destination
      {
    double distance = getDistance(origin, destination);
    int add = 0;
    int x = destination.getx() - origin.getx();
    int y = origin.gety() - destination.gety(); // Java flips things around

    double angleRad = Math.asin(Math.abs(y) / distance);
    double angleDeg = Math.toDegrees(angleRad);

    if ((x >= 0) && (y >= 0)) // Quadrant 1
    {
      angleDeg = angleDeg;
    }
    if ((x < 0) && (y > 0)) // Quadrant 2
    {
      angleDeg = 180 - angleDeg;
    }
    if ((x <= 0) && (y <= 0)) // Quadrant 3
    {
      angleDeg = 180 + angleDeg;
    }
    if ((x > 0) && (y < 0)) // Quadrant 4
    {
      angleDeg = 360 - angleDeg;
    }

    float angleFloat = Math.round(angleDeg);
    int angleInt = Math.round(angleFloat);

    return (angleInt);
  }
Ejemplo n.º 25
0
 /*12. 求二叉树中节点的最大距离
     具体分析(http://blog.csdn.net/lalor/article/details/7626678)
     即二叉树中相距最远的两个节点之间的距离。
     递归解法:
     (1)如果二叉树为空,返回0,同时记录左子树和右子树的深度,都为0
     (2)如果二叉树不为空,最大距离要么是左子树中的最大距离,要么是右子树中的最大距离,
     要么是左子树节点中到根节点的最大距离+右子树节点中到根节点的最大距离,
     同时记录左子树和右子树节点中到根节点的最大距离。
 */
 public static int getMaxDistance(TreeNode node, int maxLeft, int maxRight) {
   // maxLeft, 左子树中的节点距离左子树根节点的最远距离
   // maxRight, 右子树中的节点距离左子树根节点的最远距离
   if (node == null) {
     maxLeft = 0;
     maxRight = 0;
     return 0;
   }
   int maxLL = 0, maxLR = 0, maxRL = 0, maxRR = 0;
   int maxDistLeft, maxDistRight;
   if (node.left != null) {
     maxDistLeft = getMaxDistance(node.left, maxLL, maxLR);
     maxLeft = Math.max(maxLL, maxLR) + 1;
   } else {
     maxDistLeft = 0;
     maxLeft = 0;
   }
   if (node.right != null) {
     maxDistRight = getMaxDistance(node.right, maxRL, maxRR);
     maxRight = Math.max(maxRL, maxRR) + 1;
   } else {
     maxDistRight = 0;
     maxRight = 0;
   }
   int result = Math.max(Math.max(maxDistLeft, maxDistRight), maxLeft + maxRight + 1);
   return result;
 }
Ejemplo n.º 26
0
  public static int maxProduct(int[] A) {
    if (A.length == 0) {
      return 0;
    }
    if (A.length == 1 && A[0] < 0) {
      return A[0];
    }
    int max_product = 0;

    int current_max = 0;
    int current_min = 0;

    int prev_max = 1;
    int prev_min = 1;

    for (int i = 0; i < A.length; i++) {
      current_max = Math.max(Math.max(prev_max * A[i], prev_min * A[i]), A[i]);
      current_min = Math.min(Math.min(prev_max * A[i], prev_max * A[i]), A[i]);

      max_product = Math.max(max_product, current_max);

      prev_max = current_max;
      prev_min = current_min;
    }
    return max_product;
  }
Ejemplo n.º 27
0
 public Trap makeADeprecatedTrap(Environmental unlockThis) {
   Trap theTrap = null;
   int roll = (int) Math.round(Math.random() * 100.0);
   if (unlockThis instanceof Exit) {
     if (((Exit) unlockThis).hasADoor()) {
       if (((Exit) unlockThis).hasALock()) {
         if (roll < 20) theTrap = (Trap) CMClass.getAbility("Trap_Open");
         else if (roll < 80) theTrap = (Trap) CMClass.getAbility("Trap_Unlock");
         else theTrap = (Trap) CMClass.getAbility("Trap_Enter");
       } else {
         if (roll < 50) theTrap = (Trap) CMClass.getAbility("Trap_Open");
         else theTrap = (Trap) CMClass.getAbility("Trap_Enter");
       }
     } else theTrap = (Trap) CMClass.getAbility("Trap_Enter");
   } else if (unlockThis instanceof Container) {
     if (((Container) unlockThis).hasALid()) {
       if (((Container) unlockThis).hasALock()) {
         if (roll < 20) theTrap = (Trap) CMClass.getAbility("Trap_Open");
         else if (roll < 80) theTrap = (Trap) CMClass.getAbility("Trap_Unlock");
         else theTrap = (Trap) CMClass.getAbility("Trap_Get");
       } else {
         if (roll < 50) theTrap = (Trap) CMClass.getAbility("Trap_Open");
         else theTrap = (Trap) CMClass.getAbility("Trap_Get");
       }
     } else theTrap = (Trap) CMClass.getAbility("Trap_Get");
   } else if (unlockThis instanceof Item) theTrap = (Trap) CMClass.getAbility("Trap_Get");
   return theTrap;
 }
Ejemplo n.º 28
0
 public static int distanceLevel(String geohash1, String geohash2, int treeDepth) {
   long[] bits1 = decomposeLatLng(geohash1, treeDepth);
   long[] bits2 = decomposeLatLng(geohash2, treeDepth);
   long latDelta = Math.abs(bits1[1] - bits2[1]);
   long lngDelta = Math.abs(bits1[0] - bits2[0]);
   return (int) Math.max(latDelta, lngDelta);
 }
Ejemplo n.º 29
0
  public static void testTargetFeaturesAgainstImages(
      Vector<HaarFeature> features, Vector<IntegralImage> images) {
    int numberOfTrue = 0;
    int numberOfFalse = 0;

    for (IntegralImage ii : images) {
      float weightSum = 0.0f;
      float sum = 0.0f;
      for (HaarFeature hf : features) {
        //    			HaarFeature hf = allFeatures.get(slimFeature.featureNumber);
        //    			hf.threshold = slimFeature.threshold;
        float v = hf.weight * ii.evaluateAsClassifier(hf);
        sum += v;
        weightSum += hf.weight;
      }

      boolean success = (sum >= weightSum * 0.5f);
      //    		System.out.println("image " + ii.name + " is a " +  success + " : " + sum + " > " +
      // weightSum*0.5f);
      if (success) {
        numberOfTrue++;
      } else {
        numberOfFalse++;
      }
    }
    System.out.println("*************");
    System.out.println("true: " + numberOfTrue);
    System.out.println("false: " + numberOfFalse);

    int min = Math.min(numberOfFalse, numberOfTrue);
    int max = Math.max(numberOfFalse, numberOfTrue);

    float percentError = min * 100.0f / max;
    System.out.println("percentError = " + percentError);
  }
Ejemplo n.º 30
0
  public InvisibleStalker() {
    super();
    Random randomizer = new Random(System.currentTimeMillis());

    username = "******";
    setDescription("A shimmering blob of energy.");
    setDisplayText("An invisible stalker hunts here.");
    CMLib.factions().setAlignment(this, Faction.ALIGN_NEUTRAL);
    setMoney(0);
    basePhyStats.setWeight(10 + Math.abs(randomizer.nextInt() % 10));

    baseCharStats().setStat(CharStats.STAT_INTELLIGENCE, 12 + Math.abs(randomizer.nextInt() % 3));
    baseCharStats().setStat(CharStats.STAT_STRENGTH, 20);
    baseCharStats().setStat(CharStats.STAT_DEXTERITY, 13);

    basePhyStats().setDamage(16);
    basePhyStats().setSpeed(1.0);
    basePhyStats().setAbility(0);
    basePhyStats().setLevel(4);
    basePhyStats().setArmor(0);
    basePhyStats().setDisposition(basePhyStats().disposition() | PhyStats.IS_INVISIBLE);

    baseState.setHitPoints(CMLib.dice().roll(basePhyStats().level(), 20, basePhyStats().level()));

    addBehavior(CMClass.getBehavior("Aggressive"));
    addBehavior(CMClass.getBehavior("Mobile"));

    recoverMaxState();
    resetToMaxState();
    recoverPhyStats();
    recoverCharStats();
  }