<commit_before>#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "highlevel_feature_extractor.h"
#include <rcsc/common/server_param.h>

using namespace rcsc;

HighLevelFeatureExtractor::HighLevelFeatureExtractor(int num_teammates,
                                                     int num_opponents,
                                                     bool playing_offense) :
    FeatureExtractor(num_teammates, num_opponents, playing_offense)
{
  assert(numTeammates >= 0);
  assert(numOpponents >= 0);
  numFeatures = num_basic_features + features_per_teammate * numTeammates
      + features_per_opponent * numOpponents;
  feature_vec.resize(numFeatures);
}

HighLevelFeatureExtractor::~HighLevelFeatureExtractor() {}

const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
    const WorldModel& wm) {
  featIndx = 0;
  const ServerParam& SP = ServerParam::i();
  const SelfObject& self = wm.self();
  const Vector2D& self_pos = self.pos();
  const float self_ang = self.body().radian();
  const PlayerCont& teammates = wm.teammates();
  const PlayerCont& opponents = wm.opponents();
  float maxR = sqrtf(SP.pitchHalfLength() * SP.pitchHalfLength()
                     + SP.pitchHalfWidth() * SP.pitchHalfWidth());
  // features about self pos
  // Allow the agent to go 10% over the playfield in any direction
  float tolerance_x = .1 * SP.pitchHalfLength();
  float tolerance_y = .1 * SP.pitchHalfWidth();
  // figure up min, max x, y
  float min_x = 0; // Depends on offense vs defense
  float max_x = 0;
  if (playingOffense) {
    min_x = -tolerance_x;
    max_x = SP.pitchHalfLength() + tolerance_x;
  } else {
    min_x = -SP.pitchHalfLength()-tolerance_x;
    max_x = tolerance_x;
  }
  float min_y = -SP.pitchHalfWidth() - tolerance_y;
  float max_y = SP.pitchHalfWidth() + tolerance_y;
  // Feature[0]: X-postion
  // Feature[1]: Y-position
  if (valid(self)) {
    addNormFeature(self_pos.x, min_x, max_x);
    addNormFeature(self_pos.y, min_y, max_y);
  } else {
    addFeature(FEAT_INVALID);
    addFeature(FEAT_INVALID);
  }

  // Feature[2]: Self Angle
  addNormFeature(self_ang, -M_PI, M_PI); // Check for validity?<commit_msg>Staging further changes vs invalid feature errors<commit_after>#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "highlevel_feature_extractor.h"
#include <rcsc/common/server_param.h>

using namespace rcsc;

HighLevelFeatureExtractor::HighLevelFeatureExtractor(int num_teammates,
                                                     int num_opponents,
                                                     bool playing_offense) :
    FeatureExtractor(num_teammates, num_opponents, playing_offense)
{
  assert(numTeammates >= 0);
  assert(numOpponents >= 0);
  numFeatures = num_basic_features + features_per_teammate * numTeammates
      + features_per_opponent * numOpponents;
  feature_vec.resize(numFeatures);
}

HighLevelFeatureExtractor::~HighLevelFeatureExtractor() {}

const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
    const WorldModel& wm) {
  featIndx = 0;
  const ServerParam& SP = ServerParam::i();
  const SelfObject& self = wm.self();
  const Vector2D& self_pos = self.pos();
  const float self_ang = self.body().radian();
  const PlayerCont& teammates = wm.teammates();
  const PlayerCont& opponents = wm.opponents();
  float maxR = sqrtf(SP.pitchHalfLength() * SP.pitchHalfLength()
                     + SP.pitchHalfWidth() * SP.pitchHalfWidth());
  // features about self pos
  // Allow the agent to go 10% over the playfield in any direction
  float tolerance_x = .1 * SP.pitchHalfLength();
  float tolerance_y = .1 * SP.pitchHalfWidth();
  // figure up min, max x, y
  float min_x = 0; // Depends on offense vs defense
  float max_x = 0;
  if (playingOffense) {
    min_x = -tolerance_x;
    max_x = SP.pitchHalfLength() + tolerance_x;
  } else {
    min_x = -SP.pitchHalfLength()-tolerance_x;
    max_x = tolerance_x;
  }
  float min_y = -SP.pitchHalfWidth() - tolerance_y;
  float max_y = SP.pitchHalfWidth() + tolerance_y;
  // Feature[0]: X-postion
  // Feature[1]: Y-position
  if (self.posValid()) {
    addNormFeature(self_pos.x, min_x, max_x);
    addNormFeature(self_pos.y, min_y, max_y);
  } else {
    addFeature(FEAT_INVALID);
    addFeature(FEAT_INVALID);
  }

  // Feature[2]: Self Angle
  addNormFeature(self_ang, -M_PI, M_PI); // Check for validity?
{'fraction_non_alphanumeric': 0.11371923427529626, 'fraction_numerical': 0.005925250683682771, 'mean_word_length': 3.3541666666666665, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1866658', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1420, 'n_words': 317}