Commit c3709896 authored by drallensmith's avatar drallensmith

Working on feedback

parent 235f6aa1
......@@ -83,6 +83,8 @@ 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):
......@@ -166,3 +168,12 @@ class HFOEnvironment(object):
def getNumOpponents(self):
""" 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 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" {
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
......@@ -123,6 +123,10 @@ int HFOEnvironment::getNumOpponents() {
return agent->getNumOpponents();
}
int HFOEnvironment::getLastActionStatus(action_t last_action) {
return agent->getLastActionStatus(last_action);
}
Player HFOEnvironment::playerOnBall() {
return agent->getPlayerOnBall();
}
......
......@@ -55,6 +55,8 @@ class HFOEnvironment {
// Returns the number of opponents
virtual int getNumOpponents();
virtual int getLastActionStatus(action_t last_action);
// Get the current player holding the ball
virtual Player playerOnBall();
......
......@@ -150,6 +150,10 @@ Agent::Agent()
// set communication planner
M_communication = Communication::Ptr(new SampleCommunication());
// setup last_action variables
last_action_with_status = NOOP;
last_action_status = -1;
}
Agent::~Agent() {
......@@ -162,6 +166,23 @@ int Agent::getUnum() {
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 result = PlayerAgent::initImpl(cmd_parser);
......@@ -249,55 +270,55 @@ void Agent::actionImpl() {
}
switch(requested_action) {
case DASH:
this->doDash(params[0], params[1]);
addLastActionStatus(DASH, this->doDash(params[0], params[1]));
break;
case TURN:
this->doTurn(params[0]);
addLastActionStatus(TURN, this->doTurn(params[0]));
break;
case TACKLE:
this->doTackle(params[0], false);
addLastActionStatus(TACKLE, this->doTackle(params[0], false));
break;
case KICK:
this->doKick(params[0], params[1]);
addLastActionStatus(KICK, this->doKick(params[0], params[1]));
break;
case KICK_TO:
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])),
params[2], params[2] * 0.99, 3).execute(this);
params[2], params[2] * 0.99, 3).execute(this));
}
break;
case MOVE_TO:
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,
ServerParam::i().maxDashPower()).execute(this);
ServerParam::i().maxDashPower()).execute(this));
}
break;
case DRIBBLE_TO:
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,
ServerParam::i().maxDashPower(), 2).execute(this);
ServerParam::i().maxDashPower(), 2).execute(this));
}
break;
case INTERCEPT:
Body_Intercept().execute(this);
addLastActionStatus(INTERCEPT, Body_Intercept().execute(this));
break;
case MOVE:
this->doMove();
addLastActionStatus(MOVE, this->doMove());
break;
case SHOOT:
this->doSmartKick();
addLastActionStatus(SHOOT, this->doSmartKick());
break;
case PASS:
this->doPassTo(int(params[0]));
addLastActionStatus(PASS, this->doPassTo(int(params[0])));
break;
case DRIBBLE:
this->doDribble();
addLastActionStatus(DRIBBLE, this->doDribble());
break;
case CATCH:
this->doCatch();
addLastActionStatus(CATCH, this->doCatch());
break;
case NOOP:
break;
......@@ -306,16 +327,16 @@ void Agent::actionImpl() {
handleExit();
return;
case REDUCE_ANGLE_TO_GOAL:
this->doReduceAngleToGoal();
addLastActionStatus(REDUCE_ANGLE_TO_GOAL, this->doReduceAngleToGoal());
break;
case MARK_PLAYER:
this->doMarkPlayer(int(params[0]));
addLastActionStatus(MARK_PLAYER, this->doMarkPlayer(int(params[0])));
break;
case DEFEND_GOAL:
this->doDefendGoal();
addLastActionStatus(DEFEND_GOAL, this->doDefendGoal());
break;
case GO_TO_BALL:
this->doGoToBall();
addLastActionStatus(GO_TO_BALL, this->doGoToBall());
break;
default:
std::cerr << "ERROR: Unsupported Action: "
......@@ -730,9 +751,8 @@ Agent::doSmartKick()
ShootGenerator::instance().courses(this->world(), false);
ShootGenerator::Container::const_iterator best_shoot
= 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);
return true;
}
......@@ -754,8 +774,7 @@ Agent::doPassTo(int receiver)
{
Force_Pass pass;
pass.get_pass_to_player(this->world(), receiver);
pass.execute(this);
return true;
return pass.execute(this);
}
/*-------------------------------------------------------------------*/
......@@ -765,6 +784,7 @@ Agent::doPassTo(int receiver)
bool
Agent::doDribble()
{
bool success = false;
Strategy::instance().update( world() );
M_field_evaluator = createFieldEvaluator();
CompositeActionGenerator * g = new CompositeActionGenerator();
......@@ -772,10 +792,13 @@ Agent::doDribble()
M_action_generator = ActionGenerator::ConstPtr(g);
ActionChainHolder::instance().setFieldEvaluator( M_field_evaluator );
ActionChainHolder::instance().setActionGenerator( M_action_generator );
doPreprocess();
success = doPreprocess();
ActionChainHolder::instance().update( world() );
Bhv_ChainAction(ActionChainHolder::instance().graph()).execute(this);
if (Bhv_ChainAction(ActionChainHolder::instance().graph()).execute(this)) {
return true;
} else {
return success;
}
}
/*-------------------------------------------------------------------*/
......@@ -787,8 +810,7 @@ Agent::doMove()
{
Strategy::instance().update( world() );
int role_num = Strategy::i().roleNumber(world().self().unum());
Bhv_BasicMove().execute(this);
return true;
return Bhv_BasicMove().execute(this);
}
/*-------------------------------------------------------------------*/
......@@ -831,8 +853,7 @@ bool Agent::doMarkPlayer(int unum) {
}
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;
Body_GoToPoint(Vector2D(x,y), 0.25, ServerParam::i().maxDashPower()).execute(this);
return true;
return Body_GoToPoint(Vector2D(x,y), 0.25, ServerParam::i().maxDashPower()).execute(this);
}
/*-------------------------------------------------------------------*/
......@@ -853,7 +874,12 @@ bool Agent::doReduceAngleToGoal() {
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;
const PlayerPtrCont::const_iterator o_t_end = wm.teammatesFromSelf().end();
......@@ -919,8 +945,7 @@ bool Agent::doReduceAngleToGoal() {
double dist_to_end2 = targetLineEnd2.dist2(ball_pos);
double ratio = dist_to_end2/(dist_to_end1+dist_to_end2);
Vector2D target = targetLineEnd1 * ratio + targetLineEnd2 * (1-ratio);
Body_GoToPoint(target, 0.25, ServerParam::i().maxDashPower()).execute(this);
return true;
return Body_GoToPoint(target, 0.25, ServerParam::i().maxDashPower()).execute(this);
}
/*-------------------------------------------------------------------*/
......@@ -934,13 +959,17 @@ bool Agent::doDefendGoal() {
const WorldModel & wm = this->world();
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 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_post2 = goal_pos2.dist2(ball_pos);
double ratio = dist_to_post2/(dist_to_post1+dist_to_post2);
Vector2D target = goal_pos1 * ratio + goal_pos2 * (1-ratio);
Body_GoToPoint(target, 0.25, ServerParam::i().maxDashPower()).execute(this);
return true;
return Body_GoToPoint(target, 0.25, ServerParam::i().maxDashPower()).execute(this);
}
/*-------------------------------------------------------------------*/
......@@ -953,8 +982,11 @@ bool Agent::doDefendGoal() {
bool Agent::doGoToBall() {
const WorldModel & wm = this->world();
Body_GoToPoint(wm.ball().pos(), 0.25, ServerParam::i().maxDashPower()).execute(this);
return true;
const BallObject& ball = wm.ball();
if (! ball.rposValid()) {
return false;
}
return Body_GoToPoint(ball.pos(), 0.25, ServerParam::i().maxDashPower()).execute(this);
}
/*-------------------------------------------------------------------*/
......
......@@ -63,6 +63,8 @@ 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
int last_action_status; // Recorded return status of last action (1 = true, 0 = false, -1 = not available)
public:
inline const std::vector<float>& getState() { return state; }
......@@ -72,6 +74,7 @@ protected:
int getUnum(); // Returns the uniform number of the player
inline int getNumTeammates() { return num_teammates; }
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 std::vector<float>* mutable_params() { return &params; }
......@@ -94,6 +97,7 @@ protected:
bool doDefendGoal();
bool doGoToBall();
bool doNewAction1();
void addLastActionStatus(hfo::action_t last_action, bool action_status);
Communication::Ptr M_communication;
......
......@@ -60,6 +60,7 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
{
dlog.addText( Logger::TEAM,
__FILE__": Bhv_BasicMove" );
bool success = true;
//-----------------------------------------------
// tackle
......@@ -84,16 +85,21 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
{
dlog.addText( Logger::TEAM,
__FILE__": intercept" );
Body_Intercept().execute( agent );
success = Body_Intercept().execute( agent );
agent->setNeckAction( new Neck_OffensiveInterceptNeck() );
return true;
return success;
}
const Vector2D target_point = Strategy::i().getPosition( wm.self().unum() );
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;
dlog.addText( Logger::TEAM,
......@@ -108,10 +114,13 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
if ( ! Body_GoToPoint( target_point, dist_thr, dash_power
).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 )
{
agent->setNeckAction( new Neck_TurnToBall() );
......@@ -121,5 +130,5 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
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