Skip to content

Commit

Permalink
Merge pull request #6 from CLSFramework/structure
Browse files Browse the repository at this point in the history
change structure
  • Loading branch information
naderzare authored Sep 4, 2024
2 parents cdf543d + db490c0 commit 5411e12
Show file tree
Hide file tree
Showing 24 changed files with 451 additions and 307 deletions.
20 changes: 20 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions idl/grpc/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -840,6 +841,7 @@ message PlayerAction {

message PlayerActions {
repeated PlayerAction actions = 1;
bool ignore_preprocess = 2;
}

message ChangePlayerType {
Expand Down
6 changes: 4 additions & 2 deletions idl/thrift/soccer_service.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -803,7 +804,8 @@ struct PlayerAction {
}

struct PlayerActions {
1: list<PlayerAction> actions
1: list<PlayerAction> actions,
2: bool ignore_preprocess
}

struct ChangePlayerType {
Expand Down
2 changes: 1 addition & 1 deletion src/grpc-client/grpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void GrpcClient::sendInitMessage(bool offline_logging) const
}
}

bool GrpcClient::Register() const
bool GrpcClient::Register()
{
ClientContext context;
protos::RegisterRequest request;
Expand Down
11 changes: 2 additions & 9 deletions src/grpc-client/grpc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ using protos::TrainerAction;

class GrpcClient : public IRpcClient{
public:
protos::AgentType M_agent_type;
std::string M_target;
std::shared_ptr<Channel> M_channel;
std::unique_ptr<Game::Stub> 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() {}
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/grpc-client/grpc_client_coach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rcsc::CoachAgent *>(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;
Expand Down
4 changes: 2 additions & 2 deletions src/grpc-client/grpc_client_coach.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions src/grpc-client/grpc_client_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rcsc::PlayerAgent *>(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;
Expand All @@ -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;
Expand All @@ -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++)
{
Expand Down
7 changes: 4 additions & 3 deletions src/grpc-client/grpc_client_player.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/grpc-client/grpc_client_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rcsc::TrainerAgent *>(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;
Expand Down
4 changes: 2 additions & 2 deletions src/grpc-client/grpc_client_trainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/player/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 5411e12

Please sign in to comment.