Commit 7d9f7e09 authored by drallensmith's avatar drallensmith

Last_action_status as a boolean state variable

parent 59c57e88
No preview for this file type
......@@ -324,6 +324,10 @@ features.
\item [$3O$] {\textbf{X, Y, and Uniform Number of
Opponents} - For each opponent: the x-position, y-position and
uniform number of that opponent.}
\item{\textbf{Last\_Action\_Success\_Possible} - Whether there is any chance
the last action taken was successful, either in accomplishing the
usual intent of the action or in some other way such as getting out of
a goal-collision state. 1 for yes, -1 for no.}
\end{enumerate}
\begin{figure}[htp]
......@@ -518,6 +522,10 @@ low-level features:
sorted by proximity to the agent.}
\item [$O$] {\textbf{Opponent Uniform Nums} [Unum] One uniform number for each opponent active in HFO,
sorted by proximity to the player.}
\item{\textbf{Last\_Action\_Success\_Possible} [Boolean] Whether there is any chance
the last action taken was successful, either in accomplishing the
usual intent of the action or in some other way such as getting out of
a goal-collision state.}
\end{enumerate}
\section{Action Space}
......
......@@ -69,13 +69,6 @@ STATUS_STRINGS = {IN_GAME: "InGame",
OUT_OF_TIME: "OutOfTime",
SERVER_DOWN: "ServerDown"}
"""Possible action result statuses."""
ACTION_STATUS_UNKNOWN, ACTION_STATUS_BAD, ACTION_STATUS_MAYBE = list(range(-1,2))
ACTION_STATUS_MAYBE_OK = ACTION_STATUS_MAYBE # typos
ACTION_STATUS_STRINGS = {ACTION_STATUS_UNKNOWN: "Unknown",
ACTION_STATUS_BAD: "Bad",
ACTION_STATUS_MAYBE: "MaybeOK"}
"""Possible sides."""
RIGHT, NEUTRAL, LEFT = list(range(-1,2))
......@@ -204,7 +197,3 @@ class HFOEnvironment(object):
def getNumOpponents(self):
""" Returns the number of opponents of the agent """
return hfo_lib.getNumOpponents(self.obj)
def actionStatusToString(self, status):
"""Returns a string representation of an action status."""
return ACTION_STATUS_STRINGS[status]
......@@ -43,9 +43,6 @@ extern "C" {
int getUnum(hfo::HFOEnvironment *hfo) {return hfo->getUnum();}
int getNumTeammates(hfo::HFOEnvironment *hfo) {return hfo->getNumTeammates();}
int getNumOpponents(hfo::HFOEnvironment *hfo) {return hfo->getNumOpponents();}
int getLastActionStatus(hfo::HFOEnvironment *hfo, hfo::action_t last_action) {
return hfo->getLastActionStatus(last_action);
}
}
#endif
......@@ -398,7 +398,8 @@ void
Agent::UpdateFeatures()
{
if (feature_extractor != NULL) {
state = feature_extractor->ExtractFeatures(this->world());
state = feature_extractor->ExtractFeatures(this->world(),
getLastActionStatus());
}
}
......@@ -1093,7 +1094,7 @@ bool Agent::doDefendGoal() {
Vector2D goal_pos2( -ServerParam::i().pitchHalfLength() + ServerParam::i().goalAreaLength(), -ServerParam::i().goalHalfWidth() );
const BallObject& ball = wm.ball();
if (! ball.rposValid()) {
return ACTION_STATUS_BAD;
return false;
}
Vector2D ball_pos = ball.pos();
......
......@@ -57,7 +57,7 @@ using namespace rcsc;
*/
bool
Bhv_BasicMove::action_execute( PlayerAgent * agent )
Bhv_BasicMove::execute( PlayerAgent * agent )
{
dlog.addText( Logger::TEAM,
__FILE__": Bhv_BasicMove" );
......
......@@ -198,22 +198,6 @@ inline std::string StatusToString(status_t status) {
}
};
/**
* Returns a string representation of an action status.
*/
inline std::string ActionStatusToString(action_status_t status) {
switch (status) {
case ACTION_STATUS_BAD:
return "Bad";
case ACTION_STATUS_MAYBE:
return "MaybeOK";
case ACTION_STATUS_UNKNOWN:
return "Unknown";
default:
return "Invalid";
}
}
/**
* Parse a Trainer message to populate config. Returns a bool
* indicating if the struct was correctly parsed.
......
......@@ -6,6 +6,8 @@
#include <rcsc/player/player_agent.h>
#include <vector>
class Agent;
typedef std::pair<float, float> OpenAngle;
class FeatureExtractor {
......@@ -14,7 +16,8 @@ public:
virtual ~FeatureExtractor();
// Updated the state features stored in feature_vec
virtual const std::vector<float>& ExtractFeatures(const rcsc::WorldModel& wm) = 0;
virtual const std::vector<float>& ExtractFeatures(const rcsc::WorldModel& wm,
bool last_action_status) = 0;
// Record the current state
void LogFeatures();
......
......@@ -11,7 +11,7 @@ using namespace rcsc;
HighLevelFeatureExtractor::HighLevelFeatureExtractor(int num_teammates,
int num_opponents,
bool playing_offense) :
FeatureExtractor(num_teammates, num_opponents, playing_offense)
FeatureExtractor(num_teammates, num_opponents, playing_offense)
{
assert(numTeammates >= 0);
assert(numOpponents >= 0);
......@@ -23,8 +23,9 @@ HighLevelFeatureExtractor::HighLevelFeatureExtractor(int num_teammates,
HighLevelFeatureExtractor::~HighLevelFeatureExtractor() {}
const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
const WorldModel& wm) {
const std::vector<float>&
HighLevelFeatureExtractor::ExtractFeatures(const rcsc::WorldModel& wm,
bool last_action_status) {
featIndx = 0;
const ServerParam& SP = ServerParam::i();
const SelfObject& self = wm.self();
......@@ -37,7 +38,7 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
// 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();
float tolerance_y = .1 * SP.pitchHalfWidth(); // should this be SP.pitchWidth()?
// Feature[0]: X-postion
if (playingOffense) {
addNormFeature(self_pos.x, -tolerance_x, SP.pitchHalfLength() + tolerance_x);
......@@ -180,7 +181,7 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
addFeature(FEAT_INVALID);
}
if (getLastActionStatus()) {
if (last_action_status) {
addFeature(FEAT_MAX);
} else {
addFeature(FEAT_MIN);
......
......@@ -20,7 +20,8 @@ public:
virtual ~HighLevelFeatureExtractor();
// Updated the state features stored in feature_vec
virtual const std::vector<float>& ExtractFeatures(const rcsc::WorldModel& wm);
virtual const std::vector<float>& ExtractFeatures(const rcsc::WorldModel& wm,
bool last_action_status);
protected:
// Number of features for non-player objects.
......
......@@ -24,8 +24,9 @@ LowLevelFeatureExtractor::LowLevelFeatureExtractor(int num_teammates,
LowLevelFeatureExtractor::~LowLevelFeatureExtractor() {}
const std::vector<float>& LowLevelFeatureExtractor::ExtractFeatures(
const WorldModel& wm) {
const std::vector<float>&
LowLevelFeatureExtractor::ExtractFeatures(const rcsc::WorldModel& wm,
bool last_action_status) {
featIndx = 0;
const ServerParam& SP = ServerParam::i();
// ======================== SELF FEATURES ======================== //
......@@ -219,7 +220,7 @@ const std::vector<float>& LowLevelFeatureExtractor::ExtractFeatures(
addFeature(FEAT_MIN);
}
if (getLastActionStatus()) {
if (last_action_status) {
addFeature(FEAT_MAX);
} else {
addFeature(FEAT_MIN);
......
......@@ -14,7 +14,8 @@ public:
virtual ~LowLevelFeatureExtractor();
// Updated the state features stored in feature_vec
virtual const std::vector<float>& ExtractFeatures(const rcsc::WorldModel& wm);
virtual const std::vector<float>& ExtractFeatures(const rcsc::WorldModel& wm,
bool last_action_status);
protected:
// Number of features for non-player objects.
......
......@@ -257,7 +257,7 @@ SamplePlayer::actionImpl()
lastTrainerMessageTime = audioSensor().trainerMessageTime().cycle();
}
if (feature_extractor != NULL) {
feature_extractor->ExtractFeatures(this->world());
feature_extractor->ExtractFeatures(this->world(), true);
feature_extractor->LogFeatures();
}
}
......
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