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