Commit 70a2b0ed authored by Matthew Hausknecht's avatar Matthew Hausknecht

Refactored high level features.

parent c45a0d4a
...@@ -252,7 +252,7 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) { ...@@ -252,7 +252,7 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
} }
void Agent::startServer(int server_port) { void Agent::startServer(int server_port) {
std::cout << "Starting Server on Port " << server_port << std::endl; std::cout << "[Agent Server] Starting Server on Port " << server_port << std::endl;
struct sockaddr_in serv_addr, cli_addr; struct sockaddr_in serv_addr, cli_addr;
sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) { if (sockfd < 0) {
......
...@@ -41,9 +41,15 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures( ...@@ -41,9 +41,15 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
// Allow the agent to go 10% over the playfield in any direction // Allow the agent to go 10% over the playfield in any direction
float tolerance_x = .1 * SP.pitchHalfLength(); float tolerance_x = .1 * SP.pitchHalfLength();
float tolerance_y = .1 * SP.pitchHalfWidth(); float tolerance_y = .1 * SP.pitchHalfWidth();
addNormFeature(self_pos.x, -tolerance_x, SP.pitchHalfLength() + tolerance_x); if (playingOffense) { // Feature[0]: Xpostion
addNormFeature(self_pos.x, -tolerance_x, SP.pitchHalfLength() + tolerance_x);
} else {
addNormFeature(self_pos.x, -SP.pitchHalfLength()-tolerance_x, tolerance_x);
}
// Feature[1]: YPosition
addNormFeature(self_pos.y, -SP.pitchHalfWidth() - tolerance_y, addNormFeature(self_pos.y, -SP.pitchHalfWidth() - tolerance_y,
SP.pitchHalfWidth() + tolerance_y); SP.pitchHalfWidth() + tolerance_y);
// Feature[2]: Self Angle
addNormFeature(self_ang, -2*M_PI, 2*M_PI); addNormFeature(self_ang, -2*M_PI, 2*M_PI);
float r; float r;
...@@ -51,20 +57,27 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures( ...@@ -51,20 +57,27 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
// features about the ball // features about the ball
Vector2D ball_pos = wm.ball().pos(); Vector2D ball_pos = wm.ball().pos();
angleDistToPoint(self_pos, ball_pos, th, r); angleDistToPoint(self_pos, ball_pos, th, r);
// Feature[3]: Dist to ball
addNormFeature(r, 0, maxR); addNormFeature(r, 0, maxR);
// Feature[4]: Ang to ball
addNormFeature(th, -2*M_PI, 2*M_PI); addNormFeature(th, -2*M_PI, 2*M_PI);
// Feature[5]: Able to kick
addNormFeature(self.isKickable(), false, true); addNormFeature(self.isKickable(), false, true);
// features about distance to goal center // features about distance to goal center
Vector2D goalCenter(SP.pitchHalfLength(), 0); Vector2D goalCenter(SP.pitchHalfLength(), 0);
if (!playingOffense) {
goalCenter.assign(-SP.pitchHalfLength(), 0);
}
angleDistToPoint(self_pos, goalCenter, th, r); angleDistToPoint(self_pos, goalCenter, th, r);
// Feature[6]: Goal Center Distance
addNormFeature(r, 0, maxR); // Distance to goal center addNormFeature(r, 0, maxR); // Distance to goal center
// Feature[7]: Angle to goal center
addNormFeature(th, -2*M_PI, 2*M_PI); // Ang to goal center addNormFeature(th, -2*M_PI, 2*M_PI); // Ang to goal center
// Feature[8]: largest open goal angle
// features about our open angle to goal
addNormFeature(calcLargestGoalAngle(wm, self_pos), 0, M_PI); addNormFeature(calcLargestGoalAngle(wm, self_pos), 0, M_PI);
//std::cout << "goal angle: " << RAD_T_DEG * features[ind-1] << std::endl;
// teammate's open angle to goal // Feature [9+T]: teammate's open angle to goal
int detected_teammates = 0; int detected_teammates = 0;
for (PlayerCont::const_iterator it=teammates.begin(); it != teammates.end(); ++it) { for (PlayerCont::const_iterator it=teammates.begin(); it != teammates.end(); ++it) {
const PlayerObject& teammate = *it; const PlayerObject& teammate = *it;
...@@ -75,7 +88,7 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures( ...@@ -75,7 +88,7 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
} }
// Add zero features for any missing teammates // Add zero features for any missing teammates
for (int i=detected_teammates; i<numTeammates; ++i) { for (int i=detected_teammates; i<numTeammates; ++i) {
addFeature(FEAT_INVALID); addFeature(FEAT_INVALID);
} }
// dist to our closest opp // dist to our closest opp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment