@@ -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+
108167void 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;
0 commit comments