Ejemplo n.º 1
0
 public boolean playerQuantityCloseToBall() {
   double distanceOtherRobotToBall;
   int robotCloseToBall = 0;
   for (Player bluePlayer : this.world.getBlueTeam().getPlayers()) {
     distanceOtherRobotToBall =
         Math.sqrt(
             Math.pow(bluePlayer.getX() - this.world.getBall().getX(), 2)
                 + Math.pow(bluePlayer.getY() - this.world.getBall().getY(), 2));
     if (distanceOtherRobotToBall < 600) {
       robotCloseToBall++;
     }
   }
   return robotCloseToBall > 0;
 }
Ejemplo n.º 2
0
  public boolean distanceRobotBall() {

    boolean isCurrentRobotMostCloseToBall = true;

    double distanceCurrentRobotToBall =
        Math.sqrt(
            Math.pow(this.player.getX() - this.world.getBall().getX(), 2)
                + Math.pow(this.player.getY() - this.world.getBall().getY(), 2));
    double distanceOtherRobotToBall;
    if (isCurrentRobotMostCloseToBall) {
      for (Player bluePlayer : this.world.getBlueTeam().getPlayers()) {
        distanceOtherRobotToBall =
            Math.sqrt(
                Math.pow(bluePlayer.getX() - this.world.getBall().getX(), 2)
                    + Math.pow(bluePlayer.getY() - this.world.getBall().getY(), 2));
        if (distanceOtherRobotToBall < distanceCurrentRobotToBall) {
          isCurrentRobotMostCloseToBall = false;
          break;
        }
      }
    }
    if (isCurrentRobotMostCloseToBall) {
      for (Player yellowPlayer : this.world.getYellowTeam().getPlayers()) {
        distanceOtherRobotToBall =
            Math.sqrt(
                Math.pow(yellowPlayer.getX() - this.world.getBall().getX(), 2)
                    + Math.pow(yellowPlayer.getY() - this.world.getBall().getY(), 2));
        if (distanceOtherRobotToBall < distanceCurrentRobotToBall) {
          isCurrentRobotMostCloseToBall = false;
          break;
        }
      }
    }
    return isCurrentRobotMostCloseToBall;
  }