Commit 59c57e88 authored by drallensmith's avatar drallensmith

Try at putting action_status into state vector

parent 5df1cd17
...@@ -114,8 +114,6 @@ hfo_lib.getNumTeammates.argtypes = [c_void_p] ...@@ -114,8 +114,6 @@ hfo_lib.getNumTeammates.argtypes = [c_void_p]
hfo_lib.getNumTeammates.restype = c_int hfo_lib.getNumTeammates.restype = c_int
hfo_lib.getNumOpponents.argtypes = [c_void_p] hfo_lib.getNumOpponents.argtypes = [c_void_p]
hfo_lib.getNumOpponents.restype = c_int hfo_lib.getNumOpponents.restype = c_int
hfo_lib.getLastActionStatus.argtypes = [c_void_p, c_int]
hfo_lib.getLastActionStatus.restype = c_int
class HFOEnvironment(object): class HFOEnvironment(object):
def __init__(self): def __init__(self):
...@@ -207,16 +205,6 @@ class HFOEnvironment(object): ...@@ -207,16 +205,6 @@ class HFOEnvironment(object):
""" Returns the number of opponents of the agent """ """ Returns the number of opponents of the agent """
return hfo_lib.getNumOpponents(self.obj) return hfo_lib.getNumOpponents(self.obj)
def getLastActionStatus(self, last_action):
"""
If last_action is the last action with a recorded status,
returns ACTION_STATUS_MAYBE for possible success,
ACTION_STATUS_BAD for no possibility of success,
or ACTION_STATUS_UNKNOWN if unknown. If it is not the
last action with a recorded status, returns ACTION_STATUS_UNKNOWN.
"""
return hfo_lib.getLastActionStatus(self.obj, last_action)
def actionStatusToString(self, status): def actionStatusToString(self, status):
"""Returns a string representation of an action status.""" """Returns a string representation of an action status."""
return ACTION_STATUS_STRINGS[status] return ACTION_STATUS_STRINGS[status]
...@@ -123,10 +123,6 @@ int HFOEnvironment::getNumOpponents() { ...@@ -123,10 +123,6 @@ int HFOEnvironment::getNumOpponents() {
return agent->getNumOpponents(); return agent->getNumOpponents();
} }
action_status_t HFOEnvironment::getLastActionStatus(action_t last_action) {
return agent->getLastActionStatus(last_action);
}
Player HFOEnvironment::playerOnBall() { Player HFOEnvironment::playerOnBall() {
return agent->getPlayerOnBall(); return agent->getPlayerOnBall();
} }
......
...@@ -55,8 +55,6 @@ class HFOEnvironment { ...@@ -55,8 +55,6 @@ class HFOEnvironment {
// Returns the number of opponents // Returns the number of opponents
virtual int getNumOpponents(); virtual int getNumOpponents();
virtual action_status_t getLastActionStatus(action_t last_action);
// Get the current player holding the ball // Get the current player holding the ball
virtual Player playerOnBall(); virtual Player playerOnBall();
......
This diff is collapsed.
...@@ -65,8 +65,7 @@ protected: ...@@ -65,8 +65,7 @@ protected:
std::vector<float> params; // Parameters of current action std::vector<float> params; // Parameters of current action
int num_teammates; // Number of teammates int num_teammates; // Number of teammates
int num_opponents; // Number of opponents int num_opponents; // Number of opponents
hfo::action_t last_action_with_status; // Last action with a recorded return status bool last_action_status; // Recorded return status of last action
hfo::action_status_t last_action_status; // Recorded return status of last action
public: public:
inline const std::vector<float>& getState() { return state; } inline const std::vector<float>& getState() { return state; }
...@@ -76,7 +75,7 @@ protected: ...@@ -76,7 +75,7 @@ protected:
int getUnum(); // Returns the uniform number of the player int getUnum(); // Returns the uniform number of the player
inline int getNumTeammates() { return num_teammates; } inline int getNumTeammates() { return num_teammates; }
inline int getNumOpponents() { return num_opponents; } inline int getNumOpponents() { return num_opponents; }
hfo::action_status_t getLastActionStatus(hfo::action_t last_action); // if last_action is correct, returns status if available inline bool getLastActionStatus() { return last_action_status; }
inline void setFeatureSet(hfo::feature_set_t fset) { feature_set = fset; } inline void setFeatureSet(hfo::feature_set_t fset) { feature_set = fset; }
inline std::vector<float>* mutable_params() { return &params; } inline std::vector<float>* mutable_params() { return &params; }
...@@ -85,23 +84,23 @@ protected: ...@@ -85,23 +84,23 @@ protected:
private: private:
bool doPreprocess(); bool doPreprocess();
hfo::action_status_t doReorient(); bool doReorient();
hfo::action_status_t doSmartKick(); bool doSmartKick();
hfo::action_status_t doShoot(); bool doShoot();
bool doPass(); bool doPass();
hfo::action_status_t doPassTo(int receiver); bool doPassTo(int receiver);
hfo::action_status_t doDribble(); bool doDribble();
hfo::action_status_t doMove(); bool doMove();
bool doForceKick(); bool doForceKick();
bool doHeardPassReceive(); bool doHeardPassReceive();
hfo::action_status_t doMarkPlayer(int unum); bool doMarkPlayer(int unum);
bool doMarkPlayerNearIndex(int near_index); bool doMarkPlayerNearIndex(int near_index);
hfo::action_status_t doReduceAngleToGoal(); bool doReduceAngleToGoal();
hfo::action_status_t doDefendGoal(); bool doDefendGoal();
hfo::action_status_t doGoToBall(); bool doGoToBall();
bool doNewAction1(); bool doNewAction1();
void addLastActionStatus(hfo::action_t last_action, hfo::action_status_t action_status); inline void setLastActionStatus(bool likely_success) { last_action_status = likely_success; }
void addLastActionStatusCollision(hfo::action_t last_action, bool may_fix, bool likely_success); void setLastActionStatusCollision(bool may_fix, bool likely_success);
Communication::Ptr M_communication; Communication::Ptr M_communication;
......
...@@ -52,32 +52,23 @@ ...@@ -52,32 +52,23 @@
using namespace rcsc; using namespace rcsc;
bool
Bhv_BasicMove::execute( PlayerAgent * agent )
{
if (Bhv_BasicMove::action_execute(agent) == hfo::ACTION_STATUS_MAYBE) {
return true;
} else {
return false;
}
}
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
/*! /*!
*/ */
hfo::action_status_t bool
Bhv_BasicMove::action_execute( PlayerAgent * agent ) Bhv_BasicMove::action_execute( PlayerAgent * agent )
{ {
dlog.addText( Logger::TEAM, dlog.addText( Logger::TEAM,
__FILE__": Bhv_BasicMove" ); __FILE__": Bhv_BasicMove" );
hfo::action_status_t success = hfo::ACTION_STATUS_UNKNOWN; bool success = false;
bool maybe_success = true;
//----------------------------------------------- //-----------------------------------------------
// tackle // tackle
if ( Bhv_BasicTackle( 0.8, 80.0 ).execute( agent ) ) if ( Bhv_BasicTackle( 0.8, 80.0 ).execute( agent ) )
{ {
return hfo::ACTION_STATUS_MAYBE; return true;
} }
const WorldModel & wm = agent->world(); const WorldModel & wm = agent->world();
...@@ -96,7 +87,7 @@ Bhv_BasicMove::action_execute( PlayerAgent * agent ) ...@@ -96,7 +87,7 @@ Bhv_BasicMove::action_execute( PlayerAgent * agent )
{ {
dlog.addText( Logger::TEAM, dlog.addText( Logger::TEAM,
__FILE__": intercept" ); __FILE__": intercept" );
success = hfo::BooleanToActionStatus(Body_Intercept().execute( agent )); success = Body_Intercept().execute( agent );
agent->setNeckAction( new Neck_OffensiveInterceptNeck() ); agent->setNeckAction( new Neck_OffensiveInterceptNeck() );
return success; return success;
} }
...@@ -107,7 +98,7 @@ Bhv_BasicMove::action_execute( PlayerAgent * agent ) ...@@ -107,7 +98,7 @@ Bhv_BasicMove::action_execute( PlayerAgent * agent )
const BallObject& ball = wm.ball(); const BallObject& ball = wm.ball();
if (! ball.rposValid()) { if (! ball.rposValid()) {
if (! wm.self().collidesWithPost()) { if (! wm.self().collidesWithPost()) {
success = hfo::ACTION_STATUS_BAD; maybe_success = false;
} }
} }
...@@ -127,10 +118,12 @@ Bhv_BasicMove::action_execute( PlayerAgent * agent ) ...@@ -127,10 +118,12 @@ Bhv_BasicMove::action_execute( PlayerAgent * agent )
).execute( agent ) ) ).execute( agent ) )
{ {
if (! Body_TurnToBall().execute( agent )) { if (! Body_TurnToBall().execute( agent )) {
success = hfo::ACTION_STATUS_BAD; success = false;
} else {
success = maybe_success;
} }
} else if (success != hfo::ACTION_STATUS_BAD) { } else {
success = hfo::ACTION_STATUS_MAYBE; success = maybe_success;
} }
if ( wm.existKickableOpponent() && if ( wm.existKickableOpponent() &&
......
...@@ -38,7 +38,6 @@ public: ...@@ -38,7 +38,6 @@ public:
{ } { }
bool execute( rcsc::PlayerAgent * agent ); bool execute( rcsc::PlayerAgent * agent );
hfo::action_status_t action_execute( rcsc::PlayerAgent * agent );
private: private:
double getDashPower( const rcsc::PlayerAgent * agent ); double getDashPower( const rcsc::PlayerAgent * agent );
......
...@@ -53,24 +53,6 @@ enum status_t ...@@ -53,24 +53,6 @@ enum status_t
SERVER_DOWN // Server is not alive SERVER_DOWN // Server is not alive
}; };
// Action status
enum action_status_t {
ACTION_STATUS_UNKNOWN = -1, // cannot tell or invalid action # in status request
ACTION_STATUS_BAD = 0, // definitely not OK
ACTION_STATUS_MAYBE = 1, // may be OK, may not
};
/**
* Translates from boolean false (bad) or true (maybe OK) to action status
*/
inline action_status_t BooleanToActionStatus(const bool status) {
if (status) {
return ACTION_STATUS_MAYBE;
} else{
return ACTION_STATUS_BAD;
}
}
// Configuration of the HFO domain including the team names and player // Configuration of the HFO domain including the team names and player
// numbers for each team. This struct is populated by ParseConfig(). // numbers for each team. This struct is populated by ParseConfig().
struct Config { struct Config {
......
// -*-c++-*-
#ifndef FEATURE_EXTRACTOR_H #ifndef FEATURE_EXTRACTOR_H
#define FEATURE_EXTRACTOR_H #define FEATURE_EXTRACTOR_H
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "highlevel_feature_extractor.h" #include "highlevel_feature_extractor.h"
#include <rcsc/common/server_param.h> #include <rcsc/common/server_param.h>
#include "agent.h"
using namespace rcsc; using namespace rcsc;
...@@ -16,6 +17,7 @@ HighLevelFeatureExtractor::HighLevelFeatureExtractor(int num_teammates, ...@@ -16,6 +17,7 @@ HighLevelFeatureExtractor::HighLevelFeatureExtractor(int num_teammates,
assert(numOpponents >= 0); assert(numOpponents >= 0);
numFeatures = num_basic_features + features_per_teammate * numTeammates numFeatures = num_basic_features + features_per_teammate * numTeammates
+ features_per_opponent * numOpponents; + features_per_opponent * numOpponents;
numFeatures++; // action status
feature_vec.resize(numFeatures); feature_vec.resize(numFeatures);
} }
...@@ -178,6 +180,12 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures( ...@@ -178,6 +180,12 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
addFeature(FEAT_INVALID); addFeature(FEAT_INVALID);
} }
if (getLastActionStatus()) {
addFeature(FEAT_MAX);
} else {
addFeature(FEAT_MIN);
}
assert(featIndx == numFeatures); assert(featIndx == numFeatures);
// checkFeatures(); // checkFeatures();
return feature_vec; return feature_vec;
......
// -*-c++-*-
#ifndef HIGHLEVEL_FEATURE_EXTRACTOR_H #ifndef HIGHLEVEL_FEATURE_EXTRACTOR_H
#define HIGHLEVEL_FEATURE_EXTRACTOR_H #define HIGHLEVEL_FEATURE_EXTRACTOR_H
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "lowlevel_feature_extractor.h" #include "lowlevel_feature_extractor.h"
#include <rcsc/common/server_param.h> #include <rcsc/common/server_param.h>
#include "agent.h"
using namespace rcsc; using namespace rcsc;
...@@ -17,6 +18,7 @@ LowLevelFeatureExtractor::LowLevelFeatureExtractor(int num_teammates, ...@@ -17,6 +18,7 @@ LowLevelFeatureExtractor::LowLevelFeatureExtractor(int num_teammates,
numFeatures = num_basic_features + numFeatures = num_basic_features +
features_per_player * (numTeammates + numOpponents); features_per_player * (numTeammates + numOpponents);
numFeatures += numTeammates + numOpponents; // Uniform numbers numFeatures += numTeammates + numOpponents; // Uniform numbers
numFeatures++; // action state
feature_vec.resize(numFeatures); feature_vec.resize(numFeatures);
} }
...@@ -197,7 +199,7 @@ const std::vector<float>& LowLevelFeatureExtractor::ExtractFeatures( ...@@ -197,7 +199,7 @@ const std::vector<float>& LowLevelFeatureExtractor::ExtractFeatures(
detected_teammates++; detected_teammates++;
} }
} }
// Add -2 features for any missing teammates // Add -1 features for any missing teammates
for (int i=detected_teammates; i<numTeammates; ++i) { for (int i=detected_teammates; i<numTeammates; ++i) {
addFeature(FEAT_MIN); addFeature(FEAT_MIN);
} }
...@@ -212,11 +214,17 @@ const std::vector<float>& LowLevelFeatureExtractor::ExtractFeatures( ...@@ -212,11 +214,17 @@ const std::vector<float>& LowLevelFeatureExtractor::ExtractFeatures(
detected_opponents++; detected_opponents++;
} }
} }
// Add -2 features for any missing opponents // Add -1 features for any missing opponents
for (int i=detected_opponents; i<numOpponents; ++i) { for (int i=detected_opponents; i<numOpponents; ++i) {
addFeature(FEAT_MIN); addFeature(FEAT_MIN);
} }
if (getLastActionStatus()) {
addFeature(FEAT_MAX);
} else {
addFeature(FEAT_MIN);
}
assert(featIndx == numFeatures); assert(featIndx == numFeatures);
checkFeatures(); checkFeatures();
return feature_vec; return feature_vec;
......
// -*-c++-*-
#ifndef LOWLEVEL_FEATURE_EXTRACTOR_H #ifndef LOWLEVEL_FEATURE_EXTRACTOR_H
#define LOWLEVEL_FEATURE_EXTRACTOR_H #define LOWLEVEL_FEATURE_EXTRACTOR_H
......
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