forked from helios-base/helios-base
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy paththrift_client_coach.cpp
More file actions
106 lines (94 loc) · 2.86 KB
/
Copy paththrift_client_coach.cpp
File metadata and controls
106 lines (94 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "thrift_client_coach.h"
// #include "state_generator.h"
#include <rcsc/player/say_message_builder.h>
#include <rcsc/common/player_param.h>
#include "coach/sample_coach.h"
#include <chrono>
#include <rcsc/common/logger.h>
#include "thrift-client/thrift_state_generator.h"
using std::chrono::duration;
using std::chrono::duration_cast;
using std::chrono::high_resolution_clock;
using std::chrono::milliseconds;
#define DEBUG
#ifdef DEBUG
#define LOG(x) std::cout << x << std::endl
#define LOGV(x) std::cout << #x << ": " << x << std::endl
#else
#define LOG(x)
#define LOGV(x)
#endif
ThriftClientCoach::ThriftClientCoach()
{
M_agent_type = soccer::AgentType::CoachT;
}
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,
int rpc_timeout)
{
M_agent = static_cast<rcsc::CoachAgent *>(agent);
M_rpc_timeout = rpc_timeout;
M_unum = 12;
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;
if (!use_same_grpc_port)
{
port += 13;
}
this->M_server_host = target;
this->M_server_port = port;
}
void ThriftClientCoach::getActions()
{
auto agent = M_agent;
soccer::State state = generateState();
soccer::CoachActions actions;
state.register_response = M_register_response;
try
{
M_client->GetCoachActions(actions, state);
}
catch (const std::exception &e)
{
std::cerr << e.what() << std::endl;
M_is_connected = false;
return;
}
for (int i = 0; i < actions.actions.size(); i++)
{
auto action = actions.actions[i];
if (action.__isset.change_player_types)
{
const auto &changePlayerTypes = action.change_player_types;
const auto &playerType = changePlayerTypes.type;
const auto &unum = changePlayerTypes.uniform_number;
agent->doChangePlayerType(unum, playerType);
break;
}
if (action.__isset.do_helios_say_player_types)
{
auto sample_coach = dynamic_cast<SampleCoach *>(agent);
sample_coach->sayPlayerTypes();
break;
}
if (action.__isset.do_helios_substitute)
{
auto sample_coach = dynamic_cast<SampleCoach *>(agent);
sample_coach->doSubstitute();
break;
}
}
}
soccer::State ThriftClientCoach::generateState() const
{
auto &wm = M_agent->world();
soccer::WorldModel worldModel = ThriftStateGenerator::convertCoachWorldModel(wm);
soccer::State state;
state.world_model = worldModel;
return state;
}