// -*-c++-*-
/*!
\file sample_communication.cpp
\brief sample communication planner Source File
*/
/*
*Copyright:
Copyright (C) Hidehisa AKIYAMA
This code is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this code; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*EndCopyright:
*/
/////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "sample_communication.h"
#include "strategy.h"
#include <rcsc/formation/formation.h>
#include <rcsc/player/player_agent.h>
#include <rcsc/player/intercept_table.h>
#include <rcsc/player/say_message_builder.h>
#include <rcsc/player/freeform_parser.h>
#include <rcsc/common/logger.h>
#include <rcsc/common/server_param.h>
#include <rcsc/common/player_param.h>
#include <rcsc/common/audio_memory.h>
#include <rcsc/common/say_message_parser.h>
#include <cmath>
// #define DEBUG_PRINT
// #define DEBUG_PRINT_PLAYER_RECORD
using namespace rcsc;
namespace {
struct ObjectScore {
const AbstractPlayerObject * player_;
int number_;
double score_;
ObjectScore()
: player_( static_cast< AbstractPlayerObject * >( 0 ) ),
number_( -1 ),
score_( -65535.0 )
{ }
struct Compare {
bool operator()( const ObjectScore & lhs,
const ObjectScore & rhs ) const
{
return lhs.score_ > rhs.score_;
}
};
struct IllegalChecker {
bool operator()( const ObjectScore & val ) const
{
return val.score_ <= 0.1;
}
};
};
struct AbstractPlayerSelfDistCmp {
bool operator()( const AbstractPlayerObject * lhs,
const AbstractPlayerObject * rhs ) const
{
return lhs->distFromSelf() < rhs->distFromSelf();
}
};
struct AbstractPlayerBallDistCmp {
bool operator()( const AbstractPlayerObject * lhs,
const AbstractPlayerObject * rhs ) const
{
return lhs->distFromBall() < rhs->distFromBall();
}
};
struct AbstractPlayerBallXDiffCmp {
private:
AbstractPlayerBallXDiffCmp();
public:
const double ball_x_;
AbstractPlayerBallXDiffCmp( const double & ball_x )
: ball_x_( ball_x )
{ }
bool operator()( const AbstractPlayerObject * lhs,
const AbstractPlayerObject * rhs ) const
{
return std::fabs( lhs->pos().x - ball_x_ )
< std::fabs( rhs->pos().x - ball_x_ );
}
};
struct AbstractPlayerXCmp {
bool operator()( const AbstractPlayerObject * lhs,
const AbstractPlayerObject * rhs ) const
{
return lhs->pos().x < rhs->pos().x;
}
};
inline
double
distance_rate( const double & val,
const double & variance )
{
return std::exp( - std::pow( val, 2 ) / ( 2.0 * std::pow( variance, 2 ) ) );
}
inline
double
distance_from_ball( const AbstractPlayerObject * p,
const Vector2D & ball_pos,
const double & x_rate,
const double & y_rate )
{
//return p->distFromBall();
return std::sqrt( std::pow( ( p->pos().x - ball_pos.x ) * x_rate, 2 )
+ std::pow( ( p->pos().y - ball_pos.y ) * y_rate, 2 ) ); // Magic Number
}
}
/*-------------------------------------------------------------------*/
/*!
*/
SampleCommunication::SampleCommunication()
: M_current_sender_unum( Unum_Unknown ),
M_next_sender_unum( Unum_Unknown ),
M_ball_send_time( 0, 0 )
{
for ( int i = 0; i < 12; ++i )
{
M_teammate_send_time[i].assign( 0, 0 );
M_opponent_send_time[i].assign( 0, 0 );
}
}
/*-------------------------------------------------------------------*/
/*!
*/
SampleCommunication::~SampleCommunication()
{
}
/*-------------------------------------------------------------------*/
/*!
*/
bool
SampleCommunication::execute( PlayerAgent * agent )
{
if ( ! agent->config().useCommunication() )
{
return false;
}
updateCurrentSender( agent );
const WorldModel & wm = agent->world();
const bool penalty_shootout = wm.gameMode().isPenaltyKickMode();
bool say_recovery = false;
if ( wm.gameMode().type() != GameMode::PlayOn
&& ! penalty_shootout
&& currentSenderUnum() == wm.self().unum()
&& wm.self().recovery() < ServerParam::i().recoverInit() - 0.002 )
{
say_recovery = true;
sayRecovery( agent );
}
if ( wm.gameMode().type() == GameMode::BeforeKickOff
|| wm.gameMode().type() == GameMode::AfterGoal_
|| penalty_shootout )
{
return say_recovery;
}
#ifdef DEBUG_PRINT_PLAYER_RECORD
const AudioMemory::PlayerRecord::const_iterator end = agent->world().audioMemory().playerRecord().end();
for ( AudioMemory::PlayerRecord::const_iterator p = agent->world().audioMemory().playerRecord().begin();
p != end;
++p )
{
dlog.addText( Logger::COMMUNICATION,
__FILE__": PlayerRecord: time=[%d,%d] %s %d from %d",
p->first.cycle(), p->first.stopped(),
p->second.unum_ <= 11 ? "teammate" : "opponent",
p->second.unum_ <= 11 ? p->second.unum_ : p->second.unum_ - 11,
p->second.sender_ );
}
#endif
#if 1
sayBallAndPlayers( agent );
sayStamina( agent );
#else
sayBall( agent );
sayGoalie( agent );
saySelf( agent );
sayPlayers( agent );
#endif
attentiontoSomeone( agent );
return true;
}
/*-------------------------------------------------------------------*/
/*!
*/
void
SampleCommunication::updateCurrentSender( const PlayerAgent * agent )
{
const WorldModel & wm = agent->world();
if ( agent->effector().getSayMessageLength() > 0 )
{
M_current_sender_unum = wm.self().unum();
return;
}
// if ( wm.self().distFromBall() > ServerParam::i().audioCutDist() + 30.0 )
// {
// M_current_sender_unum = wm.self().unum();
// return;
// }
M_current_sender_unum = Unum_Unknown;
std::vector< int > candidate_unum;
candidate_unum.reserve( 11 );
if ( wm.ball().pos().x < -10.0
|| wm.gameMode().type() != GameMode::PlayOn )
{
//
// all players
//
for ( int unum = 1; unum <= 11; ++unum )
{
candidate_unum.push_back( unum );
}
}
else
{
//
// exclude goalie
//
const int goalie_unum = ( wm.ourGoalieUnum() != Unum_Unknown
? wm.ourGoalieUnum()
: Strategy::i().goalieUnum() );
for ( int unum = 1; unum <= 11; ++unum )
{
if ( unum != goalie_unum )
{
candidate_unum.push_back( unum );
#if 0
dlog.addText( Logger::COMMUNICATION,
__FILE__": (updateCurrentSender) field_player unum=%d",
candidate_unum.back() );
#endif
}
}
}
int val = ( wm.time().stopped() > 0
? wm.time().cycle() + wm.time().stopped()
: wm.time().cycle() );
int current = val % candidate_unum.size();
int next = ( val + 1 ) % candidate_unum.size();
M_current_sender_unum = candidate_unum[current];
M_ne
没有合适的资源?快使用搜索试试~ 我知道了~
agent2d-3.1.1.rar
共391个文件
h:82个
o:76个
po:76个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 14 下载量 75 浏览量
2021-05-09
13:22:18
上传
评论 1
收藏 15.52MB RAR 举报
温馨提示
这份代码有我的注释,更适合萌新入门,可以搭配我的Robocup2D代码解释和agent指导书一起使用
资源推荐
资源详情
资源评论
收起资源包目录
agent2d-3.1.1.rar (391个子文件)
configure.ac 4KB
Makefile.am 8KB
Makefile.am 179B
AUTHORS 46B
bootstrap 92B
ChangeLog 32KB
normal-formation.conf 21KB
defense-formation.conf 21KB
offense-formation.conf 21KB
setplay-our-formation.conf 8KB
setplay-opp-formation.conf 8KB
goalie-formation.conf 8KB
indirect-freekick-our-formation.conf 4KB
indirect-freekick-opp-formation.conf 4KB
kickin-our-formation.conf 4KB
offense-formation.conf 864B
normal-formation.conf 864B
defense-formation.conf 864B
normal-formation.conf 789B
defense-formation.conf 789B
offense-formation.conf 789B
player.conf 686B
coach.conf 610B
goal-kick-opp.conf 512B
setplay-our-formation.conf 512B
goalie-catch-opp.conf 512B
goalie-formation.conf 512B
goalie-catch-our.conf 512B
indirect-freekick-our-formation.conf 512B
goal-kick-our.conf 512B
before-kick-off.conf 512B
indirect-freekick-opp-formation.conf 512B
kickin-our-formation.conf 512B
setplay-opp-formation.conf 512B
goalie-catch-opp.conf 511B
goalie-catch-our.conf 506B
goal-kick-opp.conf 492B
goal-kick-our.conf 490B
before-kick-off.conf 490B
goalie-formation.conf 467B
goalie-catch-our.conf 467B
indirect-freekick-our-formation.conf 467B
goal-kick-our.conf 467B
before-kick-off.conf 467B
indirect-freekick-opp-formation.conf 467B
kickin-our-formation.conf 467B
setplay-opp-formation.conf 467B
goal-kick-opp.conf 467B
setplay-our-formation.conf 467B
goalie-catch-opp.conf 467B
configure 206KB
COPYING 34KB
sample_communication.cpp 72KB
strict_check_pass_generator.cpp 61KB
field_analyzer.cpp 41KB
bhv_penalty_kick.cpp 37KB
strategy.cpp 34KB
bhv_pass_kick_find_receiver.cpp 29KB
short_dribble_generator.cpp 26KB
tackle_generator.cpp 26KB
shoot_generator.cpp 25KB
self_pass_generator.cpp 25KB
bhv_goalie_basic_move.cpp 25KB
cross_generator.cpp 25KB
sample_player.cpp 24KB
action_chain_graph.cpp 23KB
bhv_set_play_indirect_free_kick.cpp 22KB
bhv_normal_dribble.cpp 21KB
bhv_set_play.cpp 20KB
sample_coach.cpp 20KB
bhv_chain_action.cpp 18KB
clear_generator.cpp 17KB
bhv_goalie_chase_ball.cpp 16KB
bhv_set_play_goal_kick.cpp 15KB
bhv_basic_tackle.cpp 14KB
bhv_set_play_kick_in.cpp 14KB
bhv_set_play_free_kick.cpp 13KB
neck_offensive_intercept_neck.cpp 11KB
bhv_basic_offensive_kick.cpp 11KB
simple_pass_checker.cpp 9KB
actgen_direct_pass.cpp 8KB
bhv_set_play_kick_off.cpp 8KB
bhv_goalie_free_kick.cpp 8KB
bhv_their_goal_kick_move.cpp 7KB
predict_state.cpp 7KB
view_tactical.cpp 7KB
sample_trainer.cpp 7KB
actgen_simple_dribble.cpp 6KB
bhv_custom_before_kick_off.cpp 6KB
neck_default_intercept_neck.cpp 6KB
bhv_strict_check_shoot.cpp 6KB
intention_receive.cpp 5KB
sample_field_evaluator.cpp 5KB
keepaway_communication.cpp 5KB
neck_turn_to_receiver.cpp 5KB
cooperative_action.cpp 4KB
bhv_go_to_static_ball.cpp 4KB
role_goalie.cpp 4KB
bhv_basic_move.cpp 4KB
role_keepaway_keeper.cpp 3KB
共 391 条
- 1
- 2
- 3
- 4
Author_天马行空
- 粉丝: 92
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页