diff --git a/ChangeLog.md b/ChangeLog.md index d6752819..eab8175b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,24 @@ # ChangeLog +## [0.1.4] - 2024-09-03 + +### Added +- + +### Fixed +- + +### Changed +- Change the structure of the RPC clients. + - Move some fields and methods in gRrpc/thrift client to the base class (```IRpcClient```). + - Add ```RpcPlayerClient``` that handles the preprocess check and execution. + - The ```ThriftPlayerClient``` and ```GrpcPlayerClient``` inherit from the ```RpcPlayerClient``` for preprocess handling. +- Preprocess: + - Add ```need_preprocess``` to the ```State``` message. + - Add ```ignore_preprocess``` to the ```PlayerActions``` message. + - Player Agents now first check whether they require preprocess actions, send the ```bool``` as the ```need_preprocess``` field in the ```State``` message. Then, if the server sends the ```ignore_preprocess=false (default value)``` to the proxy, the proxy will call ```doPreprocess``` method. If ther server sends the ```ignore_preprocess=true``` to the proxy, the proxy will not call the ```doPreprocess``` method and execute the ```PlayerActoins```. + + ## [0.1.3] - 2024-09-02 ### Added @@ -11,6 +30,7 @@ ### Changed - change input arguments names in start files (by [NaderZare](https://github.com/naderzare), [ArefSayareh](https://github.com/Arefsa78)) + ## [0.1.2] - 2024-09-01 ### Added diff --git a/idl/grpc/service.proto b/idl/grpc/service.proto index 570a123d..98608abe 100644 --- a/idl/grpc/service.proto +++ b/idl/grpc/service.proto @@ -260,6 +260,7 @@ message State { RegisterResponse register_response = 1; WorldModel world_model = 2; WorldModel full_world_model = 3; + bool need_preprocess = 4; } enum AgentType { @@ -840,6 +841,7 @@ message PlayerAction { message PlayerActions { repeated PlayerAction actions = 1; + bool ignore_preprocess = 2; } message ChangePlayerType { diff --git a/idl/thrift/soccer_service.thrift b/idl/thrift/soccer_service.thrift index 70206931..40cbe9dd 100644 --- a/idl/thrift/soccer_service.thrift +++ b/idl/thrift/soccer_service.thrift @@ -262,7 +262,8 @@ struct WorldModel { struct State { 1: RegisterResponse register_response, 2: WorldModel world_model, - 3: WorldModel full_world_model + 3: WorldModel full_world_model, + 4: bool need_preprocess } struct InitMessage { @@ -803,7 +804,8 @@ struct PlayerAction { } struct PlayerActions { - 1: list actions + 1: list actions, + 2: bool ignore_preprocess } struct ChangePlayerType { diff --git a/src/grpc-client/grpc_client.cpp b/src/grpc-client/grpc_client.cpp index 1d094337..9f36ca6f 100644 --- a/src/grpc-client/grpc_client.cpp +++ b/src/grpc-client/grpc_client.cpp @@ -417,7 +417,7 @@ void GrpcClient::sendInitMessage(bool offline_logging) const } } -bool GrpcClient::Register() const +bool GrpcClient::Register() { ClientContext context; protos::RegisterRequest request; diff --git a/src/grpc-client/grpc_client.h b/src/grpc-client/grpc_client.h index c26f6683..bbfeeb27 100644 --- a/src/grpc-client/grpc_client.h +++ b/src/grpc-client/grpc_client.h @@ -24,14 +24,10 @@ using protos::TrainerAction; class GrpcClient : public IRpcClient{ public: + protos::AgentType M_agent_type; std::string M_target; std::shared_ptr M_channel; std::unique_ptr M_stub_; - bool M_is_connected = false; - bool M_param_sent = false; - protos::AgentType M_agent_type; - int M_unum; - std::string M_team_name; protos::RegisterResponse * M_register_response = new protos::RegisterResponse(); ~GrpcClient() {} @@ -42,12 +38,9 @@ class GrpcClient : public IRpcClient{ void sendPlayerParams() const; void sendPlayerType() const; void sendInitMessage(bool offline_logging) const; - bool Register() const; + bool Register() override; void sendByeCommand() const override; bool connectToGrpcServer() override; - bool isConnected() const override{ - return M_is_connected; - } static rcsc::ViewWidth convertViewWidth(protos::ViewWidth view_width); static rcsc::SideID convertSideID(protos::Side side_id); diff --git a/src/grpc-client/grpc_client_coach.cpp b/src/grpc-client/grpc_client_coach.cpp index 06cf8a7f..c4b43ec0 100644 --- a/src/grpc-client/grpc_client_coach.cpp +++ b/src/grpc-client/grpc_client_coach.cpp @@ -28,15 +28,15 @@ GrpcClientCoach::GrpcClientCoach() M_agent_type = protos::AgentType::CoachT; } -void GrpcClientCoach::init(rcsc::CoachAgent *agent, +void GrpcClientCoach::init(rcsc::SoccerAgent *agent, std::string target, int port, bool use_same_grpc_port, bool add_20_to_grpc_port_if_right_side) { - M_agent = agent; + M_agent = static_cast(agent); M_unum = 12; - M_team_name = agent->world().ourTeamName(); + M_team_name = M_agent->world().ourTeamName(); if (add_20_to_grpc_port_if_right_side) if (M_agent->world().ourSide() == rcsc::SideID::RIGHT) port += 20; diff --git a/src/grpc-client/grpc_client_coach.h b/src/grpc-client/grpc_client_coach.h index 1a729823..d2b9c3f4 100644 --- a/src/grpc-client/grpc_client_coach.h +++ b/src/grpc-client/grpc_client_coach.h @@ -8,11 +8,11 @@ class GrpcClientCoach : public GrpcClient { public: GrpcClientCoach() ; - void init(rcsc::CoachAgent * agent, + void init(rcsc::SoccerAgent * agent, std::string target="localhost", int port=50051, bool use_same_grpc_port=true, - bool add_20_to_grpc_port_if_right_side=false); + bool add_20_to_grpc_port_if_right_side=false) override; void getActions(); State generateState() const; diff --git a/src/grpc-client/grpc_client_player.cpp b/src/grpc-client/grpc_client_player.cpp index 8cdfe60b..37439cb2 100644 --- a/src/grpc-client/grpc_client_player.cpp +++ b/src/grpc-client/grpc_client_player.cpp @@ -83,15 +83,15 @@ GrpcClientPlayer::GrpcClientPlayer() M_agent_type = protos::AgentType::PlayerT; } -void GrpcClientPlayer::init(rcsc::PlayerAgent *agent, +void GrpcClientPlayer::init(rcsc::SoccerAgent *agent, std::string target, int port, bool use_same_grpc_port, bool add_20_to_grpc_port_if_right_side) { - M_agent = agent; - M_unum = agent->world().self().unum(); - M_team_name = agent->world().ourTeamName(); + M_agent = static_cast(agent); + M_unum = M_agent->world().self().unum(); + M_team_name = M_agent->world().ourTeamName(); if (add_20_to_grpc_port_if_right_side) if (M_agent->world().ourSide() == rcsc::SideID::RIGHT) port += 20; @@ -108,7 +108,9 @@ void GrpcClientPlayer::init(rcsc::PlayerAgent *agent, void GrpcClientPlayer::getActions() { auto agent = M_agent; + bool pre_process = checkPreprocess(agent); State state = generateState(); + state.set_need_preprocess(pre_process); protos::RegisterResponse* response = new protos::RegisterResponse(*M_register_response); state.set_allocated_register_response(response); protos::PlayerActions actions; @@ -122,6 +124,16 @@ void GrpcClientPlayer::getActions() return; } + if (pre_process && !actions.ignore_preprocess()) + { + if (doPreprocess(agent)) + { + rcsc::dlog.addText( rcsc::Logger::TEAM, + __FILE__": preprocess done" ); + return; + } + } + int body_action_done = 0; for (int i = 0; i < actions.actions_size(); i++) { diff --git a/src/grpc-client/grpc_client_player.h b/src/grpc-client/grpc_client_player.h index 2e2cecb5..0b95e19d 100644 --- a/src/grpc-client/grpc_client_player.h +++ b/src/grpc-client/grpc_client_player.h @@ -1,17 +1,18 @@ #include "grpc_client.h" #include "player/sample_communication.h" +#include "rpc-client/rpc-player-client.h" -class GrpcClientPlayer : public GrpcClient { +class GrpcClientPlayer : public GrpcClient, public RpcPlayerClient { rcsc::PlayerAgent * M_agent; Communication::Ptr sample_communication; public: GrpcClientPlayer(); - void init(rcsc::PlayerAgent * agent, + void init(rcsc::SoccerAgent * agent, std::string target="localhost", int port=50051, bool use_same_grpc_port=true, - bool add_20_to_grpc_port_if_right_side=false); + bool add_20_to_grpc_port_if_right_side=false) override; void getActions(); void addSayMessage(protos::Say sayMessage) const; diff --git a/src/grpc-client/grpc_client_trainer.cpp b/src/grpc-client/grpc_client_trainer.cpp index 9cc05972..d882deec 100644 --- a/src/grpc-client/grpc_client_trainer.cpp +++ b/src/grpc-client/grpc_client_trainer.cpp @@ -27,15 +27,15 @@ GrpcClientTrainer::GrpcClientTrainer() M_agent_type = protos::AgentType::TrainerT; } -void GrpcClientTrainer::init(rcsc::TrainerAgent *agent, +void GrpcClientTrainer::init(rcsc::SoccerAgent *agent, std::string target, int port, bool use_same_grpc_port, bool add_20_to_grpc_port_if_right_side) { - M_agent = agent; + M_agent = static_cast(agent); M_unum = 13; - M_team_name = agent->world().ourTeamName(); + M_team_name = M_agent->world().ourTeamName(); if (add_20_to_grpc_port_if_right_side) if (M_agent->world().ourSide() == rcsc::SideID::RIGHT) port += 20; diff --git a/src/grpc-client/grpc_client_trainer.h b/src/grpc-client/grpc_client_trainer.h index 29f73658..65f039ce 100644 --- a/src/grpc-client/grpc_client_trainer.h +++ b/src/grpc-client/grpc_client_trainer.h @@ -6,11 +6,11 @@ class GrpcClientTrainer : public GrpcClient { public: GrpcClientTrainer() ; - void init(rcsc::TrainerAgent * agent, + void init(rcsc::SoccerAgent * agent, std::string target="localhost", int port=50051, bool use_same_grpc_port=true, - bool add_20_to_grpc_port_if_right_side=false); + bool add_20_to_grpc_port_if_right_side=false) override; void getActions(); State generateState() const; diff --git a/src/player/CMakeLists.txt b/src/player/CMakeLists.txt index 4f87ab2f..8e6242de 100644 --- a/src/player/CMakeLists.txt +++ b/src/player/CMakeLists.txt @@ -122,6 +122,7 @@ set (COMMON_SOURCES sample_player.cpp strategy.cpp main_player.cpp + ../rpc-client/rpc-player-client.cpp ) if (USE_THRIFT AND USE_GRPC) diff --git a/src/player/sample_player.cpp b/src/player/sample_player.cpp index 7ea638b4..e1691d12 100644 --- a/src/player/sample_player.cpp +++ b/src/player/sample_player.cpp @@ -285,16 +285,6 @@ SamplePlayer::actionImpl() ActionChainHolder::instance().setFieldEvaluator( M_field_evaluator ); ActionChainHolder::instance().setActionGenerator( M_action_generator ); - // - // special situations (tackle, objects accuracy, intention...) - // - if ( doPreprocess() ) - { - dlog.addText( Logger::TEAM, - __FILE__": preprocess done" ); - return; - } - // ActionChainHolder::instance().update( world() ); M_rpc_client->sendParams(this->config().offlineLogging()); M_rpc_client->getActions(); @@ -575,246 +565,7 @@ SamplePlayer::communicationImpl() } } -/*-------------------------------------------------------------------*/ -/*! -*/ -bool -SamplePlayer::doPreprocess() -{ - // check tackle expires - // check self position accuracy - // ball search - // check queued intention - // check simultaneous kick - - const WorldModel & wm = this->world(); - - dlog.addText( Logger::TEAM, - __FILE__": (doPreProcess)" ); - - // - // freezed by tackle effect - // - if ( wm.self().isFrozen() ) - { - dlog.addText( Logger::TEAM, - __FILE__": tackle wait. expires= %d", - wm.self().tackleExpires() ); - // face neck to ball - this->setViewAction( new View_Tactical() ); - this->setNeckAction( new Neck_TurnToBallOrScan( 0 ) ); - return true; - } - - // - // BeforeKickOff or AfterGoal. jump to the initial position - // - if ( wm.gameMode().type() == GameMode::BeforeKickOff - || wm.gameMode().type() == GameMode::AfterGoal_ ) - { - dlog.addText( Logger::TEAM, - __FILE__": before_kick_off" ); - Vector2D move_point = Strategy::i().getPosition( wm.self().unum() ); - Bhv_CustomBeforeKickOff( move_point ).execute( this ); - this->setViewAction( new View_Tactical() ); - return true; - } - - // - // self localization error - // - if ( ! wm.self().posValid() ) - { - dlog.addText( Logger::TEAM, - __FILE__": invalid my pos" ); - Bhv_Emergency().execute( this ); // includes change view - return true; - } - - // - // ball localization error - // - const int count_thr = ( wm.self().goalie() - ? 10 - : 5 ); - if ( wm.ball().posCount() > count_thr - || ( wm.gameMode().type() != GameMode::PlayOn - && wm.ball().seenPosCount() > count_thr + 10 ) ) - { - dlog.addText( Logger::TEAM, - __FILE__": search ball" ); - this->setViewAction( new View_Tactical() ); - Bhv_NeckBodyToBall().execute( this ); - return true; - } - - // - // set default change view - // - - this->setViewAction( new View_Tactical() ); - - // - // check shoot chance - // - if ( doShoot() ) - { - return true; - } - - // - // check queued action - // - // if ( this->doIntention() ) - // { - // std::cout<<"doIntention"<world(); - - if ( wm.gameMode().type() != GameMode::IndFreeKick_ - && wm.time().stopped() == 0 - && wm.self().isKickable() - && Bhv_StrictCheckShoot().execute( this ) ) - { - dlog.addText( Logger::TEAM, - __FILE__": shooted" ); - - // reset intention - this->setIntention( static_cast< SoccerIntention * >( 0 ) ); - return true; - } - - return false; -} - -/*-------------------------------------------------------------------*/ -/*! - -*/ -bool -SamplePlayer::doForceKick() -{ - const WorldModel & wm = this->world(); - - if ( wm.gameMode().type() == GameMode::PlayOn - && ! wm.self().goalie() - && wm.self().isKickable() - && wm.kickableOpponent() ) - { - dlog.addText( Logger::TEAM, - __FILE__": simultaneous kick" ); - this->debugClient().addMessage( "SimultaneousKick" ); - Vector2D goal_pos( ServerParam::i().pitchHalfLength(), 0.0 ); - - if ( wm.self().pos().x > 36.0 - && wm.self().pos().absY() > 10.0 ) - { - goal_pos.x = 45.0; - dlog.addText( Logger::TEAM, - __FILE__": simultaneous kick cross type" ); - } - Body_KickOneStep( goal_pos, - ServerParam::i().ballSpeedMax() - ).execute( this ); - this->setNeckAction( new Neck_ScanField() ); - return true; - } - - return false; -} - -/*-------------------------------------------------------------------*/ -/*! - -*/ -bool -SamplePlayer::doHeardPassReceive() -{ - const WorldModel & wm = this->world(); - - if ( wm.audioMemory().passTime() != wm.time() - || wm.audioMemory().pass().empty() - || wm.audioMemory().pass().front().receiver_ != wm.self().unum() ) - { - - return false; - } - - int self_min = wm.interceptTable().selfStep(); - Vector2D intercept_pos = wm.ball().inertiaPoint( self_min ); - Vector2D heard_pos = wm.audioMemory().pass().front().receive_pos_; - - dlog.addText( Logger::TEAM, - __FILE__": (doHeardPassReceive) heard_pos(%.2f %.2f) intercept_pos(%.2f %.2f)", - heard_pos.x, heard_pos.y, - intercept_pos.x, intercept_pos.y ); - - if ( ! wm.kickableTeammate() - && wm.ball().posCount() <= 1 - && wm.ball().velCount() <= 1 - && self_min < 20 - //&& intercept_pos.dist( heard_pos ) < 3.0 ) //5.0 ) - ) - { - dlog.addText( Logger::TEAM, - __FILE__": (doHeardPassReceive) intercept cycle=%d. intercept", - self_min ); - this->debugClient().addMessage( "Comm:Receive:Intercept" ); - Body_Intercept().execute( this ); - this->setNeckAction( new Neck_TurnToBall() ); - } - else - { - dlog.addText( Logger::TEAM, - __FILE__": (doHeardPassReceive) intercept cycle=%d. go to receive point", - self_min ); - this->debugClient().setTarget( heard_pos ); - this->debugClient().addMessage( "Comm:Receive:GoTo" ); - Body_GoToPoint( heard_pos, - 0.5, - ServerParam::i().maxDashPower() - ).execute( this ); - this->setNeckAction( new Neck_TurnToBall() ); - } - - this->setIntention( new IntentionReceive( heard_pos, - ServerParam::i().maxDashPower(), - 0.9, - 5, - wm.time() ) ); - return true; -} /*-------------------------------------------------------------------*/ /*! diff --git a/src/player/sample_player.h b/src/player/sample_player.h index 1770b7e1..f4f62f9d 100644 --- a/src/player/sample_player.h +++ b/src/player/sample_player.h @@ -114,10 +114,7 @@ class SamplePlayer private: - bool doPreprocess(); bool doShoot(); - bool doForceKick(); - bool doHeardPassReceive(); public: virtual diff --git a/src/rpc-client/rpc-client.h b/src/rpc-client/rpc-client.h index dc524f9d..f0b2e2ef 100644 --- a/src/rpc-client/rpc-client.h +++ b/src/rpc-client/rpc-client.h @@ -9,10 +9,28 @@ class IRpcClient { public: - virtual bool isConnected() const = 0; + bool M_is_connected = false; + int M_unum; + std::string M_team_name; + bool M_param_sent = false; + + virtual bool connectToGrpcServer() = 0; virtual void sendParams(bool offline_logging) = 0; virtual void getActions() = 0; virtual void sendByeCommand() const = 0; + virtual bool Register() = 0; + + virtual void init(rcsc::SoccerAgent * agent, + std::string target="localhost", + int port=50051, + bool use_same_grpc_port=true, + bool add_20_to_grpc_port_if_right_side=false) = 0; + + bool isConnected() const{ + return M_is_connected; + } + + }; #endif //HELIOS_BASE_RPC_CLIENT_H diff --git a/src/rpc-client/rpc-player-client.cpp b/src/rpc-client/rpc-player-client.cpp new file mode 100644 index 00000000..4ab767be --- /dev/null +++ b/src/rpc-client/rpc-player-client.cpp @@ -0,0 +1,328 @@ +#include "rpc-client/rpc-player-client.h" +#include +#include "view_tactical.h" +#include "rcsc/player/world_model.h" +#include "bhv_custom_before_kick_off.h" +#include "basic_actions/neck_turn_to_ball_or_scan.h" +#include "strategy.h" +#include "basic_actions/basic_actions.h" +#include "basic_actions/bhv_emergency.h" +#include +#include "basic_actions/body_kick_one_step.h" +#include "basic_actions/neck_scan_field.h" +#include "basic_actions/body_go_to_point.h" +#include "basic_actions/body_intercept.h" +#include "intention_receive.h" + +using namespace rcsc; + +bool +RpcPlayerClient::checkPreprocess(PlayerAgent * agent) { + // check tackle expires + // check self position accuracy + // ball search + // check queued intention + // check simultaneous kick + + const WorldModel & wm = agent->world(); + + dlog.addText( Logger::TEAM, + __FILE__": (doPreProcess)" ); + + // + // freezed by tackle effect + // + if ( wm.self().isFrozen() ) + { + dlog.addText( Logger::TEAM, + __FILE__": tackle wait. expires= %d", + wm.self().tackleExpires() ); + return true; + } + + // + // BeforeKickOff or AfterGoal. jump to the initial position + // + if ( wm.gameMode().type() == GameMode::BeforeKickOff + || wm.gameMode().type() == GameMode::AfterGoal_ ) + { + dlog.addText( Logger::TEAM, + __FILE__": before_kick_off" ); + return true; + } + + // + // self localization error + // + if ( ! wm.self().posValid() ) + { + return true; + } + + // + // ball localization error + // + const int count_thr = ( wm.self().goalie() + ? 10 + : 5 ); + if ( wm.ball().posCount() > count_thr + || ( wm.gameMode().type() != GameMode::PlayOn + && wm.ball().seenPosCount() > count_thr + 10 ) ) + { + dlog.addText( Logger::TEAM, + __FILE__": search ball" ); + return true; + } + + // + // set default change view + // + + agent->setViewAction( new View_Tactical() ); + + // + // check queued action + // + // if ( agent->doIntention() ) + // { + // std::cout<<"doIntention"<debugClient().addMessage( "SimultaneousKick" ); + Vector2D goal_pos( ServerParam::i().pitchHalfLength(), 0.0 ); + + if ( wm.self().pos().x > 36.0 + && wm.self().pos().absY() > 10.0 ) + { + goal_pos.x = 45.0; + dlog.addText( Logger::TEAM, + __FILE__": simultaneous kick cross type" ); + } + return true; + } + + // + // check pass message + // + if ( !(wm.audioMemory().passTime() != wm.time() + || wm.audioMemory().pass().empty() + || wm.audioMemory().pass().front().receiver_ != wm.self().unum()) ) + { + + return true; + } + + return false; +} + +bool +RpcPlayerClient::doPreprocess(PlayerAgent * agent) { + // check tackle expires + // check self position accuracy + // ball search + // check queued intention + // check simultaneous kick + + const WorldModel & wm = agent->world(); + + dlog.addText( Logger::TEAM, + __FILE__": (doPreProcess)" ); + + // + // freezed by tackle effect + // + if ( wm.self().isFrozen() ) + { + dlog.addText( Logger::TEAM, + __FILE__": tackle wait. expires= %d", + wm.self().tackleExpires() ); + // face neck to ball + agent->setViewAction( new View_Tactical() ); + agent->setNeckAction( new Neck_TurnToBallOrScan( 0 ) ); + return true; + } + + // + // BeforeKickOff or AfterGoal. jump to the initial position + // + if ( wm.gameMode().type() == GameMode::BeforeKickOff + || wm.gameMode().type() == GameMode::AfterGoal_ ) + { + dlog.addText( Logger::TEAM, + __FILE__": before_kick_off" ); + Vector2D move_point = Strategy::i().getPosition( wm.self().unum() ); + Bhv_CustomBeforeKickOff( move_point ).execute( agent ); + agent->setViewAction( new View_Tactical() ); + return true; + } + + // + // self localization error + // + if ( ! wm.self().posValid() ) + { + dlog.addText( Logger::TEAM, + __FILE__": invalid my pos" ); + Bhv_Emergency().execute( agent ); // includes change view + return true; + } + + // + // ball localization error + // + const int count_thr = ( wm.self().goalie() + ? 10 + : 5 ); + if ( wm.ball().posCount() > count_thr + || ( wm.gameMode().type() != GameMode::PlayOn + && wm.ball().seenPosCount() > count_thr + 10 ) ) + { + dlog.addText( Logger::TEAM, + __FILE__": search ball" ); + agent->setViewAction( new View_Tactical() ); + Bhv_NeckBodyToBall().execute( agent ); + return true; + } + + // + // set default change view + // + + agent->setViewAction( new View_Tactical() ); + + // check queued action + // + // if ( agent->doIntention() ) + // { + // std::cout<<"doIntention"<world(); + + if ( wm.gameMode().type() == GameMode::PlayOn + && ! wm.self().goalie() + && wm.self().isKickable() + && wm.kickableOpponent() ) + { + dlog.addText( Logger::TEAM, + __FILE__": simultaneous kick" ); + agent->debugClient().addMessage( "SimultaneousKick" ); + Vector2D goal_pos( ServerParam::i().pitchHalfLength(), 0.0 ); + + if ( wm.self().pos().x > 36.0 + && wm.self().pos().absY() > 10.0 ) + { + goal_pos.x = 45.0; + dlog.addText( Logger::TEAM, + __FILE__": simultaneous kick cross type" ); + } + Body_KickOneStep( goal_pos, + ServerParam::i().ballSpeedMax() + ).execute( agent ); + agent->setNeckAction( new Neck_ScanField() ); + return true; + } + + return false; +} + +/*-------------------------------------------------------------------*/ +/*! + +*/ +bool +RpcPlayerClient::doHeardPassReceive(PlayerAgent * agent) +{ + const WorldModel & wm = agent->world(); + + if ( wm.audioMemory().passTime() != wm.time() + || wm.audioMemory().pass().empty() + || wm.audioMemory().pass().front().receiver_ != wm.self().unum() ) + { + + return false; + } + + int self_min = wm.interceptTable().selfStep(); + Vector2D intercept_pos = wm.ball().inertiaPoint( self_min ); + Vector2D heard_pos = wm.audioMemory().pass().front().receive_pos_; + + dlog.addText( Logger::TEAM, + __FILE__": (doHeardPassReceive) heard_pos(%.2f %.2f) intercept_pos(%.2f %.2f)", + heard_pos.x, heard_pos.y, + intercept_pos.x, intercept_pos.y ); + + if ( ! wm.kickableTeammate() + && wm.ball().posCount() <= 1 + && wm.ball().velCount() <= 1 + && self_min < 20 + //&& intercept_pos.dist( heard_pos ) < 3.0 ) //5.0 ) + ) + { + dlog.addText( Logger::TEAM, + __FILE__": (doHeardPassReceive) intercept cycle=%d. intercept", + self_min ); + agent->debugClient().addMessage( "Comm:Receive:Intercept" ); + Body_Intercept().execute( agent ); + agent->setNeckAction( new Neck_TurnToBall() ); + } + else + { + dlog.addText( Logger::TEAM, + __FILE__": (doHeardPassReceive) intercept cycle=%d. go to receive point", + self_min ); + agent->debugClient().setTarget( heard_pos ); + agent->debugClient().addMessage( "Comm:Receive:GoTo" ); + Body_GoToPoint( heard_pos, + 0.5, + ServerParam::i().maxDashPower() + ).execute( agent ); + agent->setNeckAction( new Neck_TurnToBall() ); + } + + agent->setIntention( new IntentionReceive( heard_pos, + ServerParam::i().maxDashPower(), + 0.9, + 5, + wm.time() ) ); + + return true; +} \ No newline at end of file diff --git a/src/rpc-client/rpc-player-client.h b/src/rpc-client/rpc-player-client.h new file mode 100644 index 00000000..3e1b154d --- /dev/null +++ b/src/rpc-client/rpc-player-client.h @@ -0,0 +1,15 @@ +#ifndef RPC_PLAYER_CLIENT_H +#define RPC_PLAYER_CLIENT_H + +#include + + +class RpcPlayerClient { +public: + bool doPreprocess(rcsc::PlayerAgent* agent); + bool checkPreprocess(rcsc::PlayerAgent* agent); + bool doForceKick(rcsc::PlayerAgent * agent); + bool doHeardPassReceive(rcsc::PlayerAgent * agent); +}; + +#endif \ No newline at end of file diff --git a/src/thrift-client/thrift_client.h b/src/thrift-client/thrift_client.h index 56996d62..899d1aa6 100644 --- a/src/thrift-client/thrift_client.h +++ b/src/thrift-client/thrift_client.h @@ -25,11 +25,7 @@ class ThriftAgent : public IRpcClient{ std::shared_ptr M_transport; std::shared_ptr M_protocol; std::shared_ptr M_client; - bool M_is_connected = false; - bool M_param_sent = false; soccer::AgentType::type M_agent_type; - int M_unum; - std::string M_team_name; soccer::RegisterResponse M_register_response; ~ThriftAgent() {} @@ -40,12 +36,9 @@ class ThriftAgent : public IRpcClient{ void sendPlayerParams() const; void sendPlayerType() const; void sendInitMessage(bool offline_logging) const; - bool Register(); + bool Register() override; void sendByeCommand() const override; bool connectToGrpcServer() override; - bool isConnected() const override{ - return M_is_connected; - } static rcsc::ViewWidth convertViewWidth(soccer::ViewWidth::type view_width); static rcsc::SideID convertSideID(soccer::Side::type side_id); diff --git a/src/thrift-client/thrift_client_coach.cpp b/src/thrift-client/thrift_client_coach.cpp index 7df10251..160ceb23 100644 --- a/src/thrift-client/thrift_client_coach.cpp +++ b/src/thrift-client/thrift_client_coach.cpp @@ -28,15 +28,15 @@ ThriftClientCoach::ThriftClientCoach() M_agent_type = soccer::AgentType::CoachT; } -void ThriftClientCoach::init(rcsc::CoachAgent *agent, +void ThriftClientCoach::init(rcsc::SoccerAgent *agent, std::string target, int port, bool use_same_grpc_port, bool add_20_to_grpc_port_if_right_side) { - M_agent = agent; + M_agent = static_cast(agent); M_unum = 12; - M_team_name = agent->world().ourTeamName(); + M_team_name = M_agent->world().ourTeamName(); if (add_20_to_grpc_port_if_right_side) if (M_agent->world().ourSide() == rcsc::SideID::RIGHT) port += 20; diff --git a/src/thrift-client/thrift_client_coach.h b/src/thrift-client/thrift_client_coach.h index f34f219d..91091fed 100644 --- a/src/thrift-client/thrift_client_coach.h +++ b/src/thrift-client/thrift_client_coach.h @@ -8,11 +8,11 @@ class ThriftClientCoach : public ThriftAgent { public: ThriftClientCoach() ; - void init(rcsc::CoachAgent * agent, + void init(rcsc::SoccerAgent * agent, std::string target="localhost", int port=50051, bool use_same_grpc_port=true, - bool add_20_to_grpc_port_if_right_side=false); + bool add_20_to_grpc_port_if_right_side=false) override; void getActions(); soccer::State generateState() const; diff --git a/src/thrift-client/thrift_client_player.cpp b/src/thrift-client/thrift_client_player.cpp index 01a975a9..66db5b70 100644 --- a/src/thrift-client/thrift_client_player.cpp +++ b/src/thrift-client/thrift_client_player.cpp @@ -83,15 +83,15 @@ ThriftClientPlayer::ThriftClientPlayer() M_agent_type = soccer::AgentType::PlayerT; } -void ThriftClientPlayer::init(rcsc::PlayerAgent *agent, +void ThriftClientPlayer::init(rcsc::SoccerAgent *agent, std::string target, int port, bool use_same_grpc_port, bool add_20_to_grpc_port_if_right_side) { - M_agent = agent; - M_unum = agent->world().self().unum(); - M_team_name = agent->world().ourTeamName(); + M_agent = static_cast(agent); + M_unum = M_agent->world().self().unum(); + M_team_name = M_agent->world().ourTeamName(); if (add_20_to_grpc_port_if_right_side) if (M_agent->world().ourSide() == rcsc::SideID::RIGHT) port += 20; @@ -109,7 +109,9 @@ void ThriftClientPlayer::init(rcsc::PlayerAgent *agent, void ThriftClientPlayer::getActions() { auto agent = M_agent; + bool pre_process = checkPreprocess(agent); soccer::State state = generateState(); + state.need_preprocess = pre_process; soccer::PlayerActions actions; state.register_response = M_register_response; try @@ -121,6 +123,14 @@ void ThriftClientPlayer::getActions() M_is_connected = false; return; } + if (pre_process && !actions.ignore_preprocess) + { + if (doPreprocess(agent)){ + rcsc::dlog.addText( rcsc::Logger::TEAM, + __FILE__": preprocess done" ); + return; + } + } std::cout<<"action size:"<world().ourTeamName(); + M_agent = static_cast(agent); + M_team_name = M_agent->world().ourTeamName(); M_unum = 13; if (add_20_to_grpc_port_if_right_side) if (M_agent->world().ourSide() == rcsc::SideID::RIGHT) diff --git a/src/thrift-client/thrift_client_trainer.h b/src/thrift-client/thrift_client_trainer.h index 0ade3281..41ab1794 100644 --- a/src/thrift-client/thrift_client_trainer.h +++ b/src/thrift-client/thrift_client_trainer.h @@ -6,11 +6,11 @@ class ThriftClientTrainer : public ThriftAgent { public: ThriftClientTrainer() ; - void init(rcsc::TrainerAgent * agent, + void init(rcsc::SoccerAgent * agent, std::string target="localhost", int port=50051, bool use_same_grpc_port=true, - bool add_20_to_grpc_port_if_right_side=false); + bool add_20_to_grpc_port_if_right_side=false) override; void getActions(); soccer::State generateState() const;