Package clarkson.cs551.robocode.common

Examples of clarkson.cs551.robocode.common.Velocity


    }
    // Clear path history if not enough space
    if (paths.size() == pathLength) {
      paths.remove(0);
    }
    AbsolutePos pos = generatePos(self, event);
    if (enableLogging)
      System.out.println(pos);
    paths.add(pos);
    onNewPath(pos);
  }
View Full Code Here


    double enemyHeading = GeometricUtils.absoluteHeading(event
        .getHeadingRadians());
    double direction = Utils.normalAbsoluteAngle(heading - bearing);
    double distance = event.getDistance();
    Point2D.Double mypos = robot.getPosition();
    return new AbsolutePos(robot.getTime(), new Point2D.Double(distance
        * Math.cos(direction) + mypos.x, distance * Math.sin(direction)
        + mypos.y), mypos, new Velocity(enemyHeading,
        event.getVelocity()));
  }
View Full Code Here

   
  }

  @Override
  public void bulletFired(BasicRobot robot, Bullet bullet) {
    AbsolutePos target = paths.get(paths.size() - 1);
    double distance = GeometricUtils.getDistance(target.getMyPosition(),
        target.getPosition());
    int equiv = (int) (distance / robot.getWidth());
    statistic.fired(equiv);
  }
View Full Code Here

      current += summary[i];
    }
    if (enableLogging)
      System.out.println("Fire to interval:" + i);
    // Fire to interval i
    AbsolutePos last = paths.get(paths.size() - 1);
    double distance = GeometricUtils.getDistance(last.getMyPosition(),
        last.getPosition());
    double bulletSpeed = Rules.getBulletSpeed(firePower);
    long bulletTime = (long) Math.ceil(distance / bulletSpeed);
    double dx = bulletTime * last.getVelocity().getVx();
    double dy = bulletTime * last.getVelocity().getVy();
    double maxTheta = GeometricUtils.getRadian(last.getMyPosition(),
        new Point2D.Double(last.getX() + dx, last.getY() + dy));
    double minTheta = GeometricUtils.getRadian(last.getMyPosition(),
        new Point2D.Double(last.getX() - dx, last.getY() - dy));
    if (enableLogging) {
      System.out.println("Estimate max theta is " + maxTheta);
      System.out.println("Estimate min theta is " + minTheta);
    }
    double fireDirection = minTheta
View Full Code Here

  protected void onNewPath(AbsolutePos path) {
    if (paths.size() < 2)
      return;
    if (enableLogging)
      System.out.println("Data collection");
    AbsolutePos from = paths.get(paths.size() - 2);
    AbsolutePos to = paths.get(paths.size() - 1);

    long time = to.getTime() - from.getTime();
    double dx = time * from.getVelocity().getVx();
    double dy = time * from.getVelocity().getVy();
    if (enableLogging) {
      System.out.println("Dx is " + dx);
      System.out.println("Dy is " + dy);
    }
    double maxTheta = GeometricUtils.getRadian(from.getMyPosition(),
        new Point2D.Double(from.getX() + dx, from.getY() + dy));
    if (enableLogging)
      System.out.println("Max Theta:" + maxTheta);
    double minTheta = GeometricUtils.getRadian(from.getMyPosition(),
        new Point2D.Double(from.getX() - dx, from.getY() - dy));
    if (enableLogging)
      System.out.println("Min Theta:" + minTheta);
    double actualTheta = GeometricUtils.getRadian(from.getMyPosition(),
        to.getPosition());
    if (actualTheta > maxTheta)
      actualTheta = maxTheta;
    if (actualTheta < minTheta)
      actualTheta = minTheta;
    if (enableLogging)
View Full Code Here

  protected FireResult estimate(BasicRobot robot) {
    Point2D.Double mypos = robot.getPosition();
    if (paths.size() < 2) {
      return null;
    }
    AbsolutePos p2 = paths.get(0);
    AbsolutePos p3 = paths.get(1);

    double vx = (p3.getX() - p2.getX()) / (p3.getTime() - p2.getTime());
    double vy = (p3.getY() - p2.getY()) / (p3.getTime() - p2.getTime());

    double bulletSpeed = Rules.getBulletSpeed(firePower);

    double a = Math.pow(bulletSpeed, 2) - Math.pow(vx, 2) - Math.pow(vy, 2);
    double b = -2 * vx * p3.getX() - 2 * vy * p3.getY();
    double c = -Math.pow(p3.getX(), 2) - Math.pow(p3.getY(), 2);

    double t = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);

    // (x3+vx*t)^2+(y3+vy*t)^2) = t^2* bulletSpeed^2
    if (enableLogging)
      System.out.println("Estimate time to hit:" + t);

    Point2D.Double velopoint = new Point2D.Double(vx, vy);

    AbsolutePos newp = new AbsolutePos(p3.getTime() + (long) Math.ceil(t),
        new Point2D.Double(p3.getX() + vx * t, p3.getY() + vy * t),
        mypos, new Velocity(GeometricUtils.getRadian(velopoint),
            GeometricUtils.getDistance(velopoint)));
    if (enableLogging)
      System.out.println("New Point will be:" + newp);

    double radian = GeometricUtils.getRadian(mypos, newp.getPosition());
    double gunHeading = GeometricUtils.absoluteHeading(robot
        .getGunHeadingRadians());
    return new FireResult(gunHeading - radian, firePower);
  }
View Full Code Here

  protected FireResult estimate(BasicRobot robot) {
    Point2D.Double mypos = robot.getPosition();
    if (paths.size() < 3) {
      return null;
    }
    AbsolutePos p1 = paths.get(0);
    AbsolutePos p2 = paths.get(1);
    AbsolutePos p3 = paths.get(2);

    if (p2.getX() == p3.getX() && p2.getY() == p3.getY()) {
      // Deal with the not moving case
      return new FireResult(GeometricUtils.absoluteHeading(robot
          .getGunHeadingRadians())
          - GeometricUtils.getRadian(mypos, p3.getPosition()),
          firePower);
    }
    // x(2x0-2x1)+y(2y0-2y1) = x0^2+y0^2-x1^2-y1^2
    // x(2x1-2x2)+y(2x1-2x2) = x1^2+y1^2-x2^2-y2^2

    double a1 = 2 * (p1.getX() - p2.getX());
    double b1 = 2 * (p1.getY() - p2.getY());
    double c1 = Math.pow(p1.getX(), 2) + Math.pow(p1.getY(), 2)
        - Math.pow(p2.getX(), 2) - Math.pow(p2.getY(), 2);
    double a2 = 2 * (p2.getX() - p3.getX());
    double b2 = 2 * (p2.getY() - p3.getY());
    double c2 = Math.pow(p2.getX(), 2) + Math.pow(p2.getY(), 2)
        - Math.pow(p3.getX(), 2) - Math.pow(p3.getY(), 2);

    double y = (c1 * a2 - a1 * c2) / (b1 * a2 - a1 * b2);
    double x = (c1 - b1 * y) / a1;
    Point2D.Double center = new Point2D.Double(x, y);

    double a = Math.sqrt(Math.pow(x - p1.getX(), 2)
        + Math.pow(y - p1.getY(), 2));

    double theta2 = GeometricUtils.getRadian(center, p2.getPosition());
    double theta3 = GeometricUtils.getRadian(center, p3.getPosition());

    double thetaspeed = (theta3 - theta2) / (p3.getTime() - p2.getTime());

    double bulletSpeed = Rules.getBulletSpeed(firePower);

    int maxt = 40;
    double step = 0.01;
    double tval = 0;
    double threshold = 0.1;
    Point2D.Double testp = p3.getPosition();
    // Use numerical to simulate time of hit
    while (tval < maxt) {
      double r = bulletSpeed * tval;
      double theta = theta3 + thetaspeed * tval;
      testp = new Point2D.Double(Math.cos(theta) * a + x, Math.sin(theta)
View Full Code Here

  private RelativePos lastPosition;

  @Override
  public void enemyScanned(AdvancedRobot self, ScannedRobotEvent event) {
    lastPosition = new RelativePos(self.getHeadingRadians()
        + event.getBearingRadians(), event.getDistance());
  }
View Full Code Here

    double direction = Utils.normalAbsoluteAngle(heading - bearing);
    double distance = event.getDistance();
    Point2D.Double mypos = robot.getPosition();
    return new AbsolutePos(robot.getTime(), new Point2D.Double(distance
        * Math.cos(direction) + mypos.x, distance * Math.sin(direction)
        + mypos.y), mypos, new Velocity(enemyHeading,
        event.getVelocity()));
  }
View Full Code Here

    Point2D.Double velopoint = new Point2D.Double(vx, vy);

    AbsolutePos newp = new AbsolutePos(p3.getTime() + (long) Math.ceil(t),
        new Point2D.Double(p3.getX() + vx * t, p3.getY() + vy * t),
        mypos, new Velocity(GeometricUtils.getRadian(velopoint),
            GeometricUtils.getDistance(velopoint)));
    if (enableLogging)
      System.out.println("New Point will be:" + newp);

    double radian = GeometricUtils.getRadian(mypos, newp.getPosition());
View Full Code Here

TOP

Related Classes of clarkson.cs551.robocode.common.Velocity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.