Пример #1
0
  /**
   * <br>
   * In the first round,</br> <br>
   * In the paper the server is supposed to ask sensors for uncoded data.</br> <br>
   * We sent the maximum number of bits: 63 bits = "111111"</br> <br>
   * Sensor will encode in IEEE double format</br> <br>
   * Calculates the i (number of requested bits), as given in the paper</br>
   */
  @Override
  public String sendRequest(int sensor_id) {

    if (is_first_round[sensor_id] || sensor_id == 0 || round_number < M) {

      requested_bits[sensor_id] = maximum_number_of_bits_askable;

      return "111111";
    }

    double delta = code_book.getD();

    int i =
        (int)
            Math.ceil(
                (0.5
                        * (Math.log((sigma[sensor_id] * sigma[sensor_id]) / (delta * delta * P_e))
                            / Math.log(2.0)))
                    + 1);
    i = Math.min(i, maximum_number_of_bits_askable); // request not more that 63 bits
    i = Math.max(0, i); // request no less than 0 bits

    requested_bits[sensor_id] = i;

    String bit_string =
        tools.pad0ToFront(
            Integer.toBinaryString(i),
            bits_needed_to_represent_maximum_askable); // pad it to make length 6

    return tools.reverse(bit_string);
  }
Пример #2
0
  public static void main(String[] args) {
    double delta = 0.0001;
    double sigma = 0.005;
    double P_e = 0.01;

    int i =
        (int)
            Math.ceil(
                (0.5 * (Math.log((sigma * sigma) / (delta * delta * P_e)) / Math.log(2.0))) + 1);
    i = Math.min(i, 63); // request not more that 63 bits
    i = Math.max(0, i); // request no less than 0 bits
  }
  public void shoot(ArrayList<WorldObject> wo) {
    if (loaded < 0) {

      double maxDanger = 0;
      double n = 0;

      Vector2 displacement = new Vector2(range, 0);
      double distance;
      WorldObject target = null;
      for (WorldObject w : wo) {
        if (w instanceof AbstractEnemy) {

          displacement = w.getPosition().clone();
          displacement.subtract(position);
          distance = displacement.length();
          AbstractEnemy e = (AbstractEnemy) w;

          if (distance < range && e.getDanger() > maxDanger) {
            target = w;
            maxDanger = e.getDanger();
          }
        }
      }

      if (target != null) {
        Bullet t = setEnemyBulletHitting((AbstractEnemy) target);
        // Bullet t=new Bullet(position, damage, adamage, sdamage, projspeed, target);
        wo.add(t); // new Bullet(position, damage, adamage, sdamage, projspeed, target));
        if (Math.random() < 0.5) {
          // new SoundFile("Game Resources/Sound/shoot1.wav",1).start();
        }
        loaded = speed;
      }
    }
  }
 public Tower(Vector2 pos, String spritePath, int high, int wide) {
   super(pos);
   // sets default values so it'll work properly
   damage = 10;
   health = 100;
   range = 112 * Math.sqrt(2);
   adamage = 0;
   sdamage = 0;
   projspeed = 10;
   speed = 10;
   loaded = -10;
   cost = 0;
   rangeSelectedTiles = new ArrayList<Tile>();
   healthDisplay = false;
   loadAnimation();
   loadStats();
   maxHealth = health;
 }
 protected int getBlockDistance(double range) {
   int numBlocks = 0;
   double s2 = Math.sqrt(2);
   if (range == 16 * s2) {
     numBlocks = 0;
   } else if (range == 48 * s2) {
     numBlocks = 1;
   } else if (range == 80 * s2) {
     numBlocks = 2;
   } else if (range == 112 * s2) {
     numBlocks = 3;
   } else if (range == 144 * s2) {
     numBlocks = 4;
   } else if (range == 176 * s2) {
     numBlocks = 5;
   }
   return numBlocks;
 }
 public void Hit(double damage) {
   health -= Math.max(0, damage);
   healthDisplay = true;
 }
Пример #7
0
  @Override
  public boolean receiveData(String data, int id) {

    if (id != 0
        && round_number >= K
        && data.length() != requested_bits[id] + 1
        && data.length() != 0) {
      return false;
    }

    if (!is_first_round[id] && id != 0 && !obtained_sensor_reading[0]) {

      return false;
    }

    // first_reading / first sensor everybody is un-coded, and is assumed to be correct
    if (round_number < M || is_first_round[id] || id == 0) {

      is_first_round[id] = false;

      current_sensor_readings[id] = tools.binaryToDouble(data);

      obtained_sensor_reading[id] = true;

    } else {

      current_sensor_readings[id] = code_book.getDecodedValue(current_sensor_readings[0], data);
      obtained_sensor_reading[id] = true;
    }

    // calculate Y, prediction values, only after M readings

    if (round_number >= (M - 1)) {

      double temp = current_sensor_readings[id];
      updatePastReadings(temp, id);

      this.updateInputData(id);
      this.trainNeuralNets(id);
      this.calculatePrediction(id);
      this.updateVarianceOfPrediction(id);

    } else {

      double temp_value = current_sensor_readings[id];

      past_sensor_readings[id][M - round_number - 1] = temp_value;
    }

    diff[id] = current_sensor_readings[id] - predicted_sensor_readings[id][0];
    boolean all_received = true;
    for (int i = 0; i < number_of_sensors; i++) {

      if (!obtained_sensor_reading[i]) {

        all_received = false;
        break;
      }
    }
    if (all_received) {
      Arrays.fill(obtained_sensor_reading, false);

      round_number++;

      double average = 0.0;
      for (int i = 0; i < number_of_sensors; i++) {

        average += Math.abs(diff[i]);
      }
      // System.out.println("Total prediction error: "+average);

    }

    return true; // received the data
  }