class TouchVelChange : public RewardFunction { public: Vec lastvel; Vec currvel; static…
- User
class TouchVelChange : public RewardFunction { public: Vec last_vel; Vec curr_vel;
codestatic constexpr float MAX_EXTRAP_Z = CommonValues::GOAL_HEIGHT + 230.f; static constexpr float MIN_SCORE_TIME = 0.9f; static constexpr float MIN_TOUCH_VEL_CHANGE = 600.0f; static constexpr float MIN_TOUCH_HEIGHT = 200.0f; // Constructor takes exp as a parameter TouchVelChange() : last_vel(Vec(0, 0, 0)), curr_vel(Vec(0, 0, 0)), SCALE(SCALE), div(std::pow(CommonValues::CEILING_Z / 2 - CommonValues::BALL_RADIUS, SCALE)) {} virtual void Reset(const GameState& initialState) override { last_vel = initialState.ball.vel; curr_vel = initialState.ball.vel; } virtual void PreStep(const GameState& state) override { last_vel = curr_vel; curr_vel = state.ball.vel; } virtual float GetReward(const PlayerData& player, const GameState& state, const Action& prevAction) override { float reward = 0.0f; if (player.ballTouchedStep) { float VEL_DIFF = ((last_vel - state.ball.vel).Length()) / 4600; float TOTAL_BALL_VELOCITY = state.ball.vel.Length() / 6000; if (MIN_TOUCH_VEL_CHANGE < VEL_DIFF || MIN_TOUCH_HEIGHT < state.ball.pos.z) { float avg_height = (player.phys.pos.z + state.ball.pos.z) / 2.0f; float h0 = HeightActivation(0); float h1 = HeightActivation(CommonValues::CEILING_Z); float hx = HeightActivation(avg_height); float height_factor = std::pow((hx - h0) / (h1 - h0), 2); float wall_dist_factor = 1.0f - std::exp(-DistToClosestWall(player.phys.pos.x, player.phys.pos.y) / CommonValues::CAR_MAX_SPEED); HEIGHT_FACTOR = height_factor * (1.0f + wall_dist_factor); RG_LOG(HEIGHT_FACTOR); float REW = (VEL_DIFF + (TOTAL_BALL_VELOCITY * 0.2)) + (HEIGHT_FACTOR * 4); //RG_LOG(REW); reward = REW; } else { reward = (VEL_DIFF / 4600.0f) * (std::pow(std::min(state.ball.pos[2], CommonValues::CEILING_Z / 2) - CommonValues::BALL_RADIUS, SCALE) / div); }; //RS_LOG(vel_difference); } // Additional reward logic based on extrapolated position float goalY = RLConst::SOCCAR_GOAL_SCORE_BASE_THRESHOLD_Y * (player.team == Team::BLUE ? 1 : -1); float distToGoalY = std::abs(state.ball.pos.y - goalY); float extrapScoreTime = distToGoalY / RS_MAX(std::abs(state.ball.vel.y), 0.01f); Vec extrapScorePos = state.ball.pos + state.ball.vel * extrapScoreTime; extrapScorePos.z += CommonValues::GRAVITY_Z * (extrapScoreTime * extrapScoreTime) / 2; if (extrapScoreTime <= MIN_SCORE_TIME || extrapScorePos.z >= MAX_EXTRAP_Z) { reward = 0.0f; // Disable reward if the ball is about to score or go too high } return reward; } - Assistant
To determine the in your class, let's break down the calculations step by step.