Commit c3709896 authored by drallensmith's avatar drallensmith

Working on feedback

parent 235f6aa1
...@@ -83,6 +83,8 @@ hfo_lib.getNumTeammates.argtypes = [c_void_p] ...@@ -83,6 +83,8 @@ 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):
...@@ -166,3 +168,12 @@ class HFOEnvironment(object): ...@@ -166,3 +168,12 @@ class HFOEnvironment(object):
def getNumOpponents(self): def getNumOpponents(self):
""" 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 a 1 for possible success, 0 for no possibility of success,
or -1 if unknown. If it is not the last action with a
recorded status, returns a -1.
"""
return hfo_lib.getLastActionStatus(self.obj, last_action)
...@@ -50,6 +50,9 @@ extern "C" { ...@@ -50,6 +50,9 @@ extern "C" {
int getUnum(hfo::HFOEnvironment *hfo) {return hfo->getUnum();} int getUnum(hfo::HFOEnvironment *hfo) {return hfo->getUnum();}
int getNumTeammates(hfo::HFOEnvironment *hfo) {return hfo->getNumTeammates();} int getNumTeammates(hfo::HFOEnvironment *hfo) {return hfo->getNumTeammates();}
int getNumOpponents(hfo::HFOEnvironment *hfo) {return hfo->getNumOpponents();} int getNumOpponents(hfo::HFOEnvironment *hfo) {return hfo->getNumOpponents();}
int getLastActionStatus(hfo::HFOEnvironment *hfo, hfo::action_t last_action) {
return hfo->getLastActionStatus(last_action);
}
} }
#endif #endif
...@@ -123,6 +123,10 @@ int HFOEnvironment::getNumOpponents() { ...@@ -123,6 +123,10 @@ int HFOEnvironment::getNumOpponents() {
return agent->getNumOpponents(); return agent->getNumOpponents();
} }
int HFOEnvironment::getLastActionStatus(action_t last_action) {
return agent->getLastActionStatus(last_action);
}
Player HFOEnvironment::playerOnBall() { Player HFOEnvironment::playerOnBall() {
return agent->getPlayerOnBall(); return agent->getPlayerOnBall();
} }
......
...@@ -55,6 +55,8 @@ class HFOEnvironment { ...@@ -55,6 +55,8 @@ class HFOEnvironment {
// Returns the number of opponents // Returns the number of opponents
virtual int getNumOpponents(); virtual int getNumOpponents();
virtual int 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();
......
...@@ -150,6 +150,10 @@ Agent::Agent() ...@@ -150,6 +150,10 @@ Agent::Agent()
// set communication planner // set communication planner
M_communication = Communication::Ptr(new SampleCommunication()); M_communication = Communication::Ptr(new SampleCommunication());
// setup last_action variables
last_action_with_status = NOOP;
last_action_status = -1;
} }
Agent::~Agent() { Agent::~Agent() {
...@@ -162,6 +166,23 @@ int Agent::getUnum() { ...@@ -162,6 +166,23 @@ int Agent::getUnum() {
return world().self().unum(); return world().self().unum();
} }
int Agent::getLastActionStatus(action_t last_action) {
if (last_action == last_action_with_status) {
return last_action_status;
} else {
return -1;
}
}
void Agent::addLastActionStatus(action_t last_action, bool action_status) {
last_action_with_status = last_action;
if (action_status) {
last_action_status = 1;
} else {
last_action_status = 0;
}
}
bool Agent::initImpl(CmdLineParser & cmd_parser) { bool Agent::initImpl(CmdLineParser & cmd_parser) {
bool result = PlayerAgent::initImpl(cmd_parser); bool result = PlayerAgent::initImpl(cmd_parser);
...@@ -249,55 +270,55 @@ void Agent::actionImpl() { ...@@ -249,55 +270,55 @@ void Agent::actionImpl() {
} }
switch(requested_action) { switch(requested_action) {
case DASH: case DASH:
this->doDash(params[0], params[1]); addLastActionStatus(DASH, this->doDash(params[0], params[1]));
break; break;
case TURN: case TURN:
this->doTurn(params[0]); addLastActionStatus(TURN, this->doTurn(params[0]));
break; break;
case TACKLE: case TACKLE:
this->doTackle(params[0], false); addLastActionStatus(TACKLE, this->doTackle(params[0], false));
break; break;
case KICK: case KICK:
this->doKick(params[0], params[1]); addLastActionStatus(KICK, this->doKick(params[0], params[1]));
break; break;
case KICK_TO: case KICK_TO:
if (feature_extractor != NULL) { if (feature_extractor != NULL) {
Body_SmartKick(Vector2D(feature_extractor->absoluteXPos(params[0]), addLastActionStatus(KICK_TO, Body_SmartKick(Vector2D(feature_extractor->absoluteXPos(params[0]),
feature_extractor->absoluteYPos(params[1])), feature_extractor->absoluteYPos(params[1])),
params[2], params[2] * 0.99, 3).execute(this); params[2], params[2] * 0.99, 3).execute(this));
} }
break; break;
case MOVE_TO: case MOVE_TO:
if (feature_extractor != NULL) { if (feature_extractor != NULL) {
Body_GoToPoint(Vector2D(feature_extractor->absoluteXPos(params[0]), addLastActionStatus(MOVE_TO, Body_GoToPoint(Vector2D(feature_extractor->absoluteXPos(params[0]),
feature_extractor->absoluteYPos(params[1])), 0.25, feature_extractor->absoluteYPos(params[1])), 0.25,
ServerParam::i().maxDashPower()).execute(this); ServerParam::i().maxDashPower()).execute(this));
} }
break; break;
case DRIBBLE_TO: case DRIBBLE_TO:
if (feature_extractor != NULL) { if (feature_extractor != NULL) {
Body_Dribble(Vector2D(feature_extractor->absoluteXPos(params[0]), addLastActionStatus(DRIBBLE_TO, Body_Dribble(Vector2D(feature_extractor->absoluteXPos(params[0]),
feature_extractor->absoluteYPos(params[1])), 1.0, feature_extractor->absoluteYPos(params[1])), 1.0,
ServerParam::i().maxDashPower(), 2).execute(this); ServerParam::i().maxDashPower(), 2).execute(this));
} }
break; break;
case INTERCEPT: case INTERCEPT:
Body_Intercept().execute(this); addLastActionStatus(INTERCEPT, Body_Intercept().execute(this));
break; break;
case MOVE: case MOVE:
this->doMove(); addLastActionStatus(MOVE, this->doMove());
break; break;
case SHOOT: case SHOOT:
this->doSmartKick(); addLastActionStatus(SHOOT, this->doSmartKick());
break; break;
case PASS: case PASS:
this->doPassTo(int(params[0])); addLastActionStatus(PASS, this->doPassTo(int(params[0])));
break; break;
case DRIBBLE: case DRIBBLE:
this->doDribble(); addLastActionStatus(DRIBBLE, this->doDribble());
break; break;
case CATCH: case CATCH:
this->doCatch(); addLastActionStatus(CATCH, this->doCatch());
break; break;
case NOOP: case NOOP:
break; break;
...@@ -306,16 +327,16 @@ void Agent::actionImpl() { ...@@ -306,16 +327,16 @@ void Agent::actionImpl() {
handleExit(); handleExit();
return; return;
case REDUCE_ANGLE_TO_GOAL: case REDUCE_ANGLE_TO_GOAL:
this->doReduceAngleToGoal(); addLastActionStatus(REDUCE_ANGLE_TO_GOAL, this->doReduceAngleToGoal());
break; break;
case MARK_PLAYER: case MARK_PLAYER:
this->doMarkPlayer(int(params[0])); addLastActionStatus(MARK_PLAYER, this->doMarkPlayer(int(params[0])));
break; break;
case DEFEND_GOAL: case DEFEND_GOAL:
this->doDefendGoal(); addLastActionStatus(DEFEND_GOAL, this->doDefendGoal());
break; break;
case GO_TO_BALL: case GO_TO_BALL:
this->doGoToBall(); addLastActionStatus(GO_TO_BALL, this->doGoToBall());
break; break;
default: default:
std::cerr << "ERROR: Unsupported Action: " std::cerr << "ERROR: Unsupported Action: "
...@@ -730,9 +751,8 @@ Agent::doSmartKick() ...@@ -730,9 +751,8 @@ Agent::doSmartKick()
ShootGenerator::instance().courses(this->world(), false); ShootGenerator::instance().courses(this->world(), false);
ShootGenerator::Container::const_iterator best_shoot ShootGenerator::Container::const_iterator best_shoot
= std::min_element(cont.begin(), cont.end(), ShootGenerator::ScoreCmp()); = std::min_element(cont.begin(), cont.end(), ShootGenerator::ScoreCmp());
Body_SmartKick(best_shoot->target_point_, best_shoot->first_ball_speed_, return Body_SmartKick(best_shoot->target_point_, best_shoot->first_ball_speed_,
best_shoot->first_ball_speed_ * 0.99, 3).execute(this); best_shoot->first_ball_speed_ * 0.99, 3).execute(this);
return true;
} }
...@@ -754,8 +774,7 @@ Agent::doPassTo(int receiver) ...@@ -754,8 +774,7 @@ Agent::doPassTo(int receiver)
{ {
Force_Pass pass; Force_Pass pass;
pass.get_pass_to_player(this->world(), receiver); pass.get_pass_to_player(this->world(), receiver);
pass.execute(this); return pass.execute(this);
return true;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
...@@ -765,6 +784,7 @@ Agent::doPassTo(int receiver) ...@@ -765,6 +784,7 @@ Agent::doPassTo(int receiver)
bool bool
Agent::doDribble() Agent::doDribble()
{ {
bool success = false;
Strategy::instance().update( world() ); Strategy::instance().update( world() );
M_field_evaluator = createFieldEvaluator(); M_field_evaluator = createFieldEvaluator();
CompositeActionGenerator * g = new CompositeActionGenerator(); CompositeActionGenerator * g = new CompositeActionGenerator();
...@@ -772,10 +792,13 @@ Agent::doDribble() ...@@ -772,10 +792,13 @@ Agent::doDribble()
M_action_generator = ActionGenerator::ConstPtr(g); M_action_generator = ActionGenerator::ConstPtr(g);
ActionChainHolder::instance().setFieldEvaluator( M_field_evaluator ); ActionChainHolder::instance().setFieldEvaluator( M_field_evaluator );
ActionChainHolder::instance().setActionGenerator( M_action_generator ); ActionChainHolder::instance().setActionGenerator( M_action_generator );
doPreprocess(); success = doPreprocess();
ActionChainHolder::instance().update( world() ); ActionChainHolder::instance().update( world() );
Bhv_ChainAction(ActionChainHolder::instance().graph()).execute(this); if (Bhv_ChainAction(ActionChainHolder::instance().graph()).execute(this)) {
return true; return true;
} else {
return success;
}
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
...@@ -787,8 +810,7 @@ Agent::doMove() ...@@ -787,8 +810,7 @@ Agent::doMove()
{ {
Strategy::instance().update( world() ); Strategy::instance().update( world() );
int role_num = Strategy::i().roleNumber(world().self().unum()); int role_num = Strategy::i().roleNumber(world().self().unum());
Bhv_BasicMove().execute(this); return Bhv_BasicMove().execute(this);
return true;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
...@@ -831,8 +853,7 @@ bool Agent::doMarkPlayer(int unum) { ...@@ -831,8 +853,7 @@ bool Agent::doMarkPlayer(int unum) {
} }
double x = player_pos.x + (kicker_pos.x - player_pos.x)*0.1; double x = player_pos.x + (kicker_pos.x - player_pos.x)*0.1;
double y = player_pos.y + (kicker_pos.y - player_pos.y)*0.1; double y = player_pos.y + (kicker_pos.y - player_pos.y)*0.1;
Body_GoToPoint(Vector2D(x,y), 0.25, ServerParam::i().maxDashPower()).execute(this); return Body_GoToPoint(Vector2D(x,y), 0.25, ServerParam::i().maxDashPower()).execute(this);
return true;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
...@@ -853,7 +874,12 @@ bool Agent::doReduceAngleToGoal() { ...@@ -853,7 +874,12 @@ bool Agent::doReduceAngleToGoal() {
const PlayerPtrCont::const_iterator o_end = wm.opponentsFromSelf().end(); const PlayerPtrCont::const_iterator o_end = wm.opponentsFromSelf().end();
Vector2D ball_pos = wm.ball().pos(); const BallObject& ball = wm.ball();
if (! ball.rposValid()) {
return false;
}
Vector2D ball_pos = ball.pos();
double nearRatio = 0.9; double nearRatio = 0.9;
const PlayerPtrCont::const_iterator o_t_end = wm.teammatesFromSelf().end(); const PlayerPtrCont::const_iterator o_t_end = wm.teammatesFromSelf().end();
...@@ -919,8 +945,7 @@ bool Agent::doReduceAngleToGoal() { ...@@ -919,8 +945,7 @@ bool Agent::doReduceAngleToGoal() {
double dist_to_end2 = targetLineEnd2.dist2(ball_pos); double dist_to_end2 = targetLineEnd2.dist2(ball_pos);
double ratio = dist_to_end2/(dist_to_end1+dist_to_end2); double ratio = dist_to_end2/(dist_to_end1+dist_to_end2);
Vector2D target = targetLineEnd1 * ratio + targetLineEnd2 * (1-ratio); Vector2D target = targetLineEnd1 * ratio + targetLineEnd2 * (1-ratio);
Body_GoToPoint(target, 0.25, ServerParam::i().maxDashPower()).execute(this); return Body_GoToPoint(target, 0.25, ServerParam::i().maxDashPower()).execute(this);
return true;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
...@@ -934,13 +959,17 @@ bool Agent::doDefendGoal() { ...@@ -934,13 +959,17 @@ bool Agent::doDefendGoal() {
const WorldModel & wm = this->world(); const WorldModel & wm = this->world();
Vector2D goal_pos1( -ServerParam::i().pitchHalfLength() + ServerParam::i().goalAreaLength(), ServerParam::i().goalHalfWidth() ); Vector2D goal_pos1( -ServerParam::i().pitchHalfLength() + ServerParam::i().goalAreaLength(), ServerParam::i().goalHalfWidth() );
Vector2D goal_pos2( -ServerParam::i().pitchHalfLength() + ServerParam::i().goalAreaLength(), -ServerParam::i().goalHalfWidth() ); Vector2D goal_pos2( -ServerParam::i().pitchHalfLength() + ServerParam::i().goalAreaLength(), -ServerParam::i().goalHalfWidth() );
Vector2D ball_pos = wm.ball().pos(); const BallObject& ball = wm.ball();
if (! ball.rposValid()) {
return false;
}
Vector2D ball_pos = ball.pos();
double dist_to_post1 = goal_pos1.dist2(ball_pos); double dist_to_post1 = goal_pos1.dist2(ball_pos);
double dist_to_post2 = goal_pos2.dist2(ball_pos); double dist_to_post2 = goal_pos2.dist2(ball_pos);
double ratio = dist_to_post2/(dist_to_post1+dist_to_post2); double ratio = dist_to_post2/(dist_to_post1+dist_to_post2);
Vector2D target = goal_pos1 * ratio + goal_pos2 * (1-ratio); Vector2D target = goal_pos1 * ratio + goal_pos2 * (1-ratio);
Body_GoToPoint(target, 0.25, ServerParam::i().maxDashPower()).execute(this); return Body_GoToPoint(target, 0.25, ServerParam::i().maxDashPower()).execute(this);
return true;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
...@@ -953,8 +982,11 @@ bool Agent::doDefendGoal() { ...@@ -953,8 +982,11 @@ bool Agent::doDefendGoal() {
bool Agent::doGoToBall() { bool Agent::doGoToBall() {
const WorldModel & wm = this->world(); const WorldModel & wm = this->world();
Body_GoToPoint(wm.ball().pos(), 0.25, ServerParam::i().maxDashPower()).execute(this); const BallObject& ball = wm.ball();
return true; if (! ball.rposValid()) {
return false;
}
return Body_GoToPoint(ball.pos(), 0.25, ServerParam::i().maxDashPower()).execute(this);
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
...@@ -984,9 +1016,9 @@ Agent::doForceKick() ...@@ -984,9 +1016,9 @@ Agent::doForceKick()
dlog.addText( Logger::TEAM, dlog.addText( Logger::TEAM,
__FILE__": simultaneous kick cross type" ); __FILE__": simultaneous kick cross type" );
} }
Body_KickOneStep( goal_pos, Body_KickOneStep( goal_pos,
ServerParam::i().ballSpeedMax() ServerParam::i().ballSpeedMax()
).execute( this ); ).execute( this );
this->setNeckAction( new Neck_ScanField() ); this->setNeckAction( new Neck_ScanField() );
return true; return true;
} }
......
...@@ -63,6 +63,8 @@ protected: ...@@ -63,6 +63,8 @@ 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
int last_action_status; // Recorded return status of last action (1 = true, 0 = false, -1 = not available)
public: public:
inline const std::vector<float>& getState() { return state; } inline const std::vector<float>& getState() { return state; }
...@@ -72,6 +74,7 @@ protected: ...@@ -72,6 +74,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; }
int getLastActionStatus(hfo::action_t last_action); // if last_action is correct, returns status if available
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; }
...@@ -94,6 +97,7 @@ protected: ...@@ -94,6 +97,7 @@ protected:
bool doDefendGoal(); bool doDefendGoal();
bool doGoToBall(); bool doGoToBall();
bool doNewAction1(); bool doNewAction1();
void addLastActionStatus(hfo::action_t last_action, bool action_status);
Communication::Ptr M_communication; Communication::Ptr M_communication;
......
...@@ -60,6 +60,7 @@ Bhv_BasicMove::execute( PlayerAgent * agent ) ...@@ -60,6 +60,7 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
{ {
dlog.addText( Logger::TEAM, dlog.addText( Logger::TEAM,
__FILE__": Bhv_BasicMove" ); __FILE__": Bhv_BasicMove" );
bool success = true;
//----------------------------------------------- //-----------------------------------------------
// tackle // tackle
...@@ -84,16 +85,21 @@ Bhv_BasicMove::execute( PlayerAgent * agent ) ...@@ -84,16 +85,21 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
{ {
dlog.addText( Logger::TEAM, dlog.addText( Logger::TEAM,
__FILE__": intercept" ); __FILE__": intercept" );
Body_Intercept().execute( agent ); success = Body_Intercept().execute( agent );
agent->setNeckAction( new Neck_OffensiveInterceptNeck() ); agent->setNeckAction( new Neck_OffensiveInterceptNeck() );
return true; return success;
} }
const Vector2D target_point = Strategy::i().getPosition( wm.self().unum() ); const Vector2D target_point = Strategy::i().getPosition( wm.self().unum() );
const double dash_power = Strategy::get_normal_dash_power( wm ); const double dash_power = Strategy::get_normal_dash_power( wm );
double dist_thr = wm.ball().distFromSelf() * 0.1; const BallObject& ball = wm.ball();
if (! ball.rposValid()) {
success = false;
}
double dist_thr = ball.distFromSelf() * 0.1;
if ( dist_thr < 1.0 ) dist_thr = 1.0; if ( dist_thr < 1.0 ) dist_thr = 1.0;
dlog.addText( Logger::TEAM, dlog.addText( Logger::TEAM,
...@@ -108,10 +114,13 @@ Bhv_BasicMove::execute( PlayerAgent * agent ) ...@@ -108,10 +114,13 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
if ( ! Body_GoToPoint( target_point, dist_thr, dash_power if ( ! Body_GoToPoint( target_point, dist_thr, dash_power
).execute( agent ) ) ).execute( agent ) )
{ {
Body_TurnToBall().execute( agent ); if (! Body_TurnToBall().execute( agent )) {
success = false;
}
} }
if ( wm.existKickableOpponent() if ( wm.existKickableOpponent() &&
ball.rposValid()
&& wm.ball().distFromSelf() < 18.0 ) && wm.ball().distFromSelf() < 18.0 )
{ {
agent->setNeckAction( new Neck_TurnToBall() ); agent->setNeckAction( new Neck_TurnToBall() );
...@@ -121,5 +130,5 @@ Bhv_BasicMove::execute( PlayerAgent * agent ) ...@@ -121,5 +130,5 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
agent->setNeckAction( new Neck_TurnToBallOrScan() ); agent->setNeckAction( new Neck_TurnToBallOrScan() );
} }
return true; return success;
} }
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