相信刚开始接触Robocup 2D比赛的萌新,都清楚agent的代码看起来是很痛苦的,而且不知道从何看起。
我个人观点看代码先看bhv和role这部分的代码。bhv行为动作的类的代码涉及到球员的进攻、跑位、防守、铲球等决策。role角色类会调用bhv中的部分函数。
为了帮助萌新们更好的入门,我将我所看了的agent2d的代码添加了注释,有需要的去我的资源里面自取
以bhv_basic_move.cpp为例
bool
Bhv_BasicMove::execute( PlayerAgent * agent )
{
dlog.addText( Logger::TEAM,
__FILE__": Bhv_BasicMove" );
if ( Bhv_BasicTackle( 0.8, 80.0 ).execute( agent ) )
{
return true;
}
const WorldModel & wm = agent->world();
const int self_min = wm.interceptTable()->selfReachCycle();
const int mate_min = wm.interceptTable()->teammateReachCycle();
const int opp_min = wm.interceptTable()->opponentReachCycle();
if ( ! wm.existKickableTeammate()
&& ( self_min <= 3
|| ( self_min <= mate_min
&& self_min < opp_min + 3 )
)
)
{
dlog.addText( Logger::TEAM,
__FILE__": intercept" );
Body_Intercept().execute( agent );
agent->setNeckAction( new Neck_OffensiveInterceptNeck() );
return true;
}
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;
if ( dist_thr < 1.0 ) dist_thr = 1.0;
dlog.addText( Logger::TEAM,
__FILE__": Bhv_BasicMove target=(%.1f %.1f) dist_thr=%.2f",
target_point.x, target_point.y,
dist_thr );
agent->debugClient().addMessage( "BasicMove%.0f", dash_power );
agent->debugClient().setTarget( target_point );
agent->debugClient().addCircle( target_point, dist_thr );
if ( ! Body_GoToPoint( target_point, dist_thr, dash_power
).execute( agent ) )
{
Body_TurnToBall().execute( agent );
}
if ( wm.existKickableOpponent()
&& wm.ball().distFromSelf() < 18.0 )
{
agent->setNeckAction( new Neck_TurnToBall() );
}
else
{
agent->setNeckAction( new Neck_TurnToBallOrScan() );
}
return true;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)