Skip to content

Commit 1f1b7dd

Browse files
authored
Merge pull request #42 from CLSFramework/fix-performance-bug
Fix performance bug and server side decision making
2 parents 408cc53 + 131506b commit 1f1b7dd

30 files changed

+1555
-320
lines changed

idl/grpc/service.proto

Lines changed: 413 additions & 13 deletions
Large diffs are not rendered by default.

idl/thrift/soccer_service.thrift

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// version 1.6
1+
// version 1.7
22

33
namespace cpp soccer
44
namespace py soccer
@@ -761,6 +761,58 @@ struct HeliosGoalieKick {}
761761

762762
struct HeliosShoot {}
763763

764+
struct OpponentEffector {
765+
1: list<double> negetive_effect_by_distance,
766+
2: bool negetive_effect_by_distance_based_on_first_layer,
767+
3: list<double> negetive_effect_by_reach_steps,
768+
4: bool negetive_effect_by_reach_steps_based_on_first_layer
769+
}
770+
771+
struct ActionTypeEffector {
772+
1: double direct_pass,
773+
2: double lead_pass,
774+
3: double through_pass,
775+
4: double short_dribble,
776+
5: double long_dribble,
777+
6: double cross,
778+
7: double hold
779+
}
780+
781+
struct TeammateEffector {
782+
1: map<i32, double> coefficients,
783+
2: bool apply_based_on_first_layer
784+
}
785+
786+
struct PlannerEvaluationEffector {
787+
1: optional OpponentEffector opponent_effector,
788+
2: optional ActionTypeEffector action_type_effector,
789+
3: optional TeammateEffector teammate_effector
790+
}
791+
792+
struct HeliosFieldEvaluator {
793+
1: double x_coefficient,
794+
2: double ball_dist_to_goal_coefficient,
795+
3: double effective_max_ball_dist_to_goal
796+
}
797+
798+
struct MatrixFieldEvaluatorY {
799+
1: list<double> evals
800+
}
801+
802+
struct MatrixFieldEvaluator {
803+
1: list<MatrixFieldEvaluatorY> evals
804+
}
805+
806+
struct PlannerFieldEvaluator {
807+
1: optional HeliosFieldEvaluator helios_field_evaluator,
808+
2: optional MatrixFieldEvaluator matrix_field_evaluator
809+
}
810+
811+
struct PlannerEvaluation {
812+
1: PlannerEvaluationEffector effectors,
813+
2: PlannerFieldEvaluator field_evaluators
814+
}
815+
764816
struct HeliosOffensivePlanner {
765817
1: bool direct_pass,
766818
2: bool lead_pass,
@@ -771,7 +823,10 @@ struct HeliosOffensivePlanner {
771823
7: bool simple_pass,
772824
8: bool simple_dribble,
773825
9: bool simple_shoot
774-
10: bool server_side_decision
826+
10: bool server_side_decision,
827+
11: i32 max_depth,
828+
12: i32 max_nodes,
829+
13: PlannerEvaluation evaluation
775830
}
776831

777832
struct HeliosBasicOffensive {}
@@ -861,7 +916,9 @@ struct PlayerActions {
861916
1: list<PlayerAction> actions,
862917
2: bool ignore_preprocess,
863918
3: bool ignore_doforcekick,
864-
4: bool ignore_doHeardPassRecieve
919+
4: bool ignore_doHeardPassRecieve,
920+
5: bool ignore_doIntention,
921+
6: bool ignore_shootInPreprocess
865922
}
866923

867924
struct ChangePlayerType {

src/grpc-client/grpc_client_player.cpp

Lines changed: 195 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,65 @@ void GrpcClientPlayer::init(rcsc::SoccerAgent *agent,
105105
sample_communication = Communication::Ptr(new SampleCommunication());
106106
}
107107

108+
void GrpcClientPlayer::updateChainByDefault(const rcsc::WorldModel &wm)
109+
{
110+
FieldEvaluator::ConstPtr field_evaluator = FieldEvaluator::ConstPtr(new SampleFieldEvaluator);
111+
CompositeActionGenerator *g = new CompositeActionGenerator();
112+
113+
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_StrictCheckPass(), 1));
114+
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_Cross(), 1));
115+
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_ShortDribble(), 1));
116+
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_SelfPass(), 1));
117+
118+
g->addGenerator(new ActGen_RangeActionChainLengthFilter(new ActGen_Shoot(),
119+
2, ActGen_RangeActionChainLengthFilter::MAX));
120+
ActionGenerator::ConstPtr action_generator = ActionGenerator::ConstPtr(g);
121+
ActionChainHolder::instance().setFieldEvaluator(field_evaluator);
122+
ActionChainHolder::instance().setActionGenerator(action_generator);
123+
ActionChainHolder::instance().update(wm);
124+
}
125+
126+
void GrpcClientPlayer::updateChainByPlannerAction(const rcsc::WorldModel &wm, const protos::PlayerAction &action)
127+
{
128+
CompositeActionGenerator *g = new CompositeActionGenerator();
129+
if (action.helios_offensive_planner().max_depth() > 0)
130+
g->max_depth = action.helios_offensive_planner().max_depth();
131+
if (action.helios_offensive_planner().max_nodes() > 0)
132+
g->max_nodes = action.helios_offensive_planner().max_nodes();
133+
134+
FieldEvaluator::Ptr field_evaluator = FieldEvaluator::Ptr(new SampleFieldEvaluator);
135+
if (action.helios_offensive_planner().has_evaluation())
136+
field_evaluator->set_grpc_evalution_method(action.helios_offensive_planner().evaluation());
137+
138+
if (action.helios_offensive_planner().lead_pass()
139+
|| action.helios_offensive_planner().direct_pass() || action.helios_offensive_planner().through_pass())
140+
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_StrictCheckPass(), 1));
141+
if (action.helios_offensive_planner().cross())
142+
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_Cross(), 1));
143+
if (action.helios_offensive_planner().simple_pass())
144+
g->addGenerator(new ActGen_RangeActionChainLengthFilter(new ActGen_DirectPass(),
145+
2, ActGen_RangeActionChainLengthFilter::MAX));
146+
if (action.helios_offensive_planner().short_dribble())
147+
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_ShortDribble(), 1));
148+
if (action.helios_offensive_planner().long_dribble())
149+
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_SelfPass(), 1));
150+
if (action.helios_offensive_planner().simple_dribble())
151+
g->addGenerator(new ActGen_RangeActionChainLengthFilter(new ActGen_SimpleDribble(),
152+
2, ActGen_RangeActionChainLengthFilter::MAX));
153+
if (action.helios_offensive_planner().simple_shoot())
154+
g->addGenerator(new ActGen_RangeActionChainLengthFilter(new ActGen_Shoot(),
155+
2, ActGen_RangeActionChainLengthFilter::MAX));
156+
if (g->M_generators.empty())
157+
{
158+
return;
159+
}
160+
ActionGenerator::ConstPtr action_generator = ActionGenerator::ConstPtr(g);
161+
162+
ActionChainHolder::instance().setFieldEvaluator(field_evaluator);
163+
ActionChainHolder::instance().setActionGenerator(action_generator);
164+
ActionChainHolder::instance().update(wm);
165+
}
166+
108167
void GrpcClientPlayer::getActions()
109168
{
110169
auto agent = M_agent;
@@ -117,12 +176,21 @@ void GrpcClientPlayer::getActions()
117176
state.set_allocated_register_response(response);
118177
protos::PlayerActions actions;
119178
ClientContext context;
179+
// Set the deadline to 1 second from now
180+
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(1);
181+
context.set_deadline(deadline);
182+
120183
Status status = M_stub_->GetPlayerActions(&context, state, &actions);
121184

122185
if (!status.ok())
123186
{
124-
std::cout << status.error_code() << ": " << status.error_message()
187+
std::cout << "rpcerror:" << status.error_code() << ": " << status.error_message()
125188
<< std::endl;
189+
190+
if (status.error_code() == grpc::StatusCode::DEADLINE_EXCEEDED) {
191+
// The call timed out
192+
std::cerr << "rpcerror-timeout" << std::endl;
193+
}
126194
return;
127195
}
128196

@@ -135,6 +203,28 @@ void GrpcClientPlayer::getActions()
135203
return;
136204
}
137205
}
206+
const rcsc::WorldModel & wm = agent->world();
207+
208+
if ( !actions.ignore_shootinpreprocess() )
209+
{
210+
if ( wm.gameMode().type() != rcsc::GameMode::IndFreeKick_
211+
&& wm.time().stopped() == 0
212+
&& wm.self().isKickable()
213+
&& Bhv_StrictCheckShoot().execute( agent ) )
214+
{
215+
// reset intention
216+
agent->setIntention( static_cast< rcsc::SoccerIntention * >( 0 ) );
217+
return;
218+
}
219+
}
220+
221+
if ( !actions.ignore_dointention() )
222+
{
223+
if ( agent->doIntention() )
224+
{
225+
return;
226+
}
227+
}
138228

139229
if (do_forceKick && !actions.ignore_doforcekick())
140230
{
@@ -145,7 +235,7 @@ void GrpcClientPlayer::getActions()
145235
return;
146236
}
147237
}
148-
238+
149239
if (do_heardPassReceive && !actions.ignore_doheardpassrecieve())
150240
{
151241
if (doHeardPassReceive(agent))
@@ -155,6 +245,102 @@ void GrpcClientPlayer::getActions()
155245
return;
156246
}
157247
}
248+
249+
// if (agent->world().gameMode().type() == rcsc::GameMode::PlayOn)
250+
// {
251+
// if (agent->world().self().goalie())
252+
// {
253+
// protos::PlayerAction action;
254+
// action.set_allocated_helios_goalie(new protos::HeliosGoalie());
255+
// actions.add_actions()->CopyFrom(action);
256+
// }
257+
// else if (agent->world().self().isKickable())
258+
// {
259+
// const auto &wm = agent->world();
260+
// protos::PlayerAction action;
261+
262+
// auto planner = new protos::HeliosOffensivePlanner();
263+
// planner->set_direct_pass(true);
264+
// planner->set_lead_pass(true);
265+
// planner->set_through_pass(true);
266+
// planner->set_short_dribble(true);
267+
// planner->set_long_dribble(true);
268+
// planner->set_cross(true);
269+
// planner->set_simple_pass(false);
270+
// planner->set_simple_dribble(false);
271+
// planner->set_simple_shoot(true);
272+
273+
// action.set_allocated_helios_offensive_planner(planner);
274+
// actions.add_actions()->CopyFrom(action);
275+
// }
276+
// else
277+
// {
278+
// protos::PlayerAction action;
279+
// auto move = new protos::HeliosBasicMove();
280+
// action.set_allocated_helios_basic_move(move);
281+
// actions.add_actions()->CopyFrom(action);
282+
// }
283+
// }
284+
// else
285+
// {
286+
// protos::PlayerAction action;
287+
// auto set_play = new protos::HeliosSetPlay();
288+
// action.set_allocated_helios_set_play(set_play);
289+
// actions.add_actions()->CopyFrom(action);
290+
// }
291+
292+
int planner_action_index = -1;
293+
for (int i = 0; i < actions.actions_size(); i++)
294+
{
295+
auto action = actions.actions(i);
296+
if (action.action_case() == PlayerAction::kHeliosOffensivePlanner)
297+
{
298+
planner_action_index = i;
299+
break;
300+
}
301+
}
302+
303+
if (planner_action_index != -1)
304+
{
305+
updateChainByPlannerAction(wm, actions.actions(planner_action_index));
306+
}
307+
else
308+
{
309+
updateChainByDefault(wm);
310+
}
311+
312+
// if (agent->world().gameMode().type() == rcsc::GameMode::PlayOn)
313+
// {
314+
// if (agent->world().self().goalie())
315+
// {
316+
// RoleGoalie().execute(agent);
317+
// return;
318+
// }
319+
// else if (agent->world().self().isKickable())
320+
// {
321+
// const auto &wm = agent->world();
322+
// if (Bhv_PlannedAction().execute(agent))
323+
// {
324+
// agent->debugClient().addMessage("PlannedAction");
325+
// }
326+
// else
327+
// {
328+
// Body_HoldBall().execute(agent);
329+
// agent->setNeckAction(new Neck_ScanField());
330+
// }
331+
// }
332+
// else
333+
// {
334+
// Bhv_BasicMove().execute(agent);
335+
// return;
336+
// }
337+
// }
338+
// else
339+
// {
340+
// Bhv_SetPlay().execute(agent);
341+
// return;
342+
// }
343+
158344

159345
for (int i = 0; i < actions.actions_size(); i++)
160346
{
@@ -543,38 +729,6 @@ void GrpcClientPlayer::getActions()
543729
}
544730
}
545731
else if (action.action_case() == PlayerAction::kHeliosOffensivePlanner) {
546-
FieldEvaluator::ConstPtr field_evaluator = FieldEvaluator::ConstPtr(new SampleFieldEvaluator);
547-
CompositeActionGenerator *g = new CompositeActionGenerator();
548-
549-
if (action.helios_offensive_planner().lead_pass()
550-
|| action.helios_offensive_planner().direct_pass() || action.helios_offensive_planner().through_pass())
551-
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_StrictCheckPass(), 1));
552-
if (action.helios_offensive_planner().cross())
553-
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_Cross(), 1));
554-
if (action.helios_offensive_planner().simple_pass())
555-
g->addGenerator(new ActGen_RangeActionChainLengthFilter(new ActGen_DirectPass(),
556-
2, ActGen_RangeActionChainLengthFilter::MAX));
557-
if (action.helios_offensive_planner().short_dribble())
558-
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_ShortDribble(), 1));
559-
if (action.helios_offensive_planner().long_dribble())
560-
g->addGenerator(new ActGen_MaxActionChainLengthFilter(new ActGen_SelfPass(), 1));
561-
if (action.helios_offensive_planner().simple_dribble())
562-
g->addGenerator(new ActGen_RangeActionChainLengthFilter(new ActGen_SimpleDribble(),
563-
2, ActGen_RangeActionChainLengthFilter::MAX));
564-
if (action.helios_offensive_planner().simple_shoot())
565-
g->addGenerator(new ActGen_RangeActionChainLengthFilter(new ActGen_Shoot(),
566-
2, ActGen_RangeActionChainLengthFilter::MAX));
567-
if (g->M_generators.empty())
568-
{
569-
Body_HoldBall().execute(agent);
570-
agent->setNeckAction(new Neck_ScanField());
571-
continue;
572-
}
573-
ActionGenerator::ConstPtr action_generator = ActionGenerator::ConstPtr(g);
574-
ActionChainHolder::instance().setFieldEvaluator(field_evaluator);
575-
ActionChainHolder::instance().setActionGenerator(action_generator);
576-
ActionChainHolder::instance().update(agent->world());
577-
578732
if (action.helios_offensive_planner().server_side_decision())
579733
{
580734
if (GetBestPlannerAction())
@@ -588,7 +742,11 @@ void GrpcClientPlayer::getActions()
588742
{
589743
agent->debugClient().addMessage("PlannedAction");
590744
}
591-
745+
else
746+
{
747+
Body_HoldBall().execute(agent);
748+
agent->setNeckAction(new Neck_ScanField());
749+
}
592750
}
593751

594752
}
@@ -630,14 +788,15 @@ bool GrpcClientPlayer::GetBestPlannerAction()
630788
<< std::endl;
631789
return false;
632790
}
791+
ActionChainHolder::instance().updateBestChain(best_action.index());
633792

634793
auto agent = M_agent;
635794

636795
#ifdef DEBUG_CLIENT_PLAYER
637796
std::cout << "best action index:" << best_action.index() << std::endl;
638797
#endif
639798

640-
if (Bhv_PlannedAction().execute(agent, best_action.index()))
799+
if (Bhv_PlannedAction().execute(agent))
641800
{
642801
#ifdef DEBUG_CLIENT_PLAYER
643802
std::cout << "PlannedAction" << std::endl;

src/grpc-client/grpc_client_player.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class GrpcClientPlayer : public GrpcClient, public RpcPlayerClient
1616
bool use_same_grpc_port = true,
1717
bool add_20_to_grpc_port_if_right_side = false) override;
1818

19+
void updateChainByDefault(const rcsc::WorldModel &wm);
20+
void updateChainByPlannerAction(const rcsc::WorldModel &wm, const protos::PlayerAction &action);
1921
void getActions();
2022
bool GetBestPlannerAction();
2123
void convertResultPairToRpcActionStatePair( google::protobuf::Map<int32_t, protos::RpcActionState> * map);

0 commit comments

Comments
 (0)