Skip to content

Commit e5ebad8

Browse files
committed
fix server side dec making
1 parent 78a5a91 commit e5ebad8

File tree

8 files changed

+90
-70
lines changed

8 files changed

+90
-70
lines changed

src/grpc-client/grpc_client_player.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,14 +788,15 @@ bool GrpcClientPlayer::GetBestPlannerAction()
788788
<< std::endl;
789789
return false;
790790
}
791+
ActionChainHolder::instance().updateBestChain(best_action.index());
791792

792793
auto agent = M_agent;
793794

794795
#ifdef DEBUG_CLIENT_PLAYER
795796
std::cout << "best action index:" << best_action.index() << std::endl;
796797
#endif
797798

798-
if (Bhv_PlannedAction().execute(agent, best_action.index()))
799+
if (Bhv_PlannedAction().execute(agent))
799800
{
800801
#ifdef DEBUG_CLIENT_PLAYER
801802
std::cout << "PlannedAction" << std::endl;

src/player/planner/action_chain_graph.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,3 +853,46 @@ ActionChainGraph::write_chain_log( const std::string & pre_log_message,
853853
}
854854
}
855855
}
856+
857+
/*-------------------------------------------------------------------*/
858+
/*!
859+
860+
*/
861+
void
862+
ActionChainGraph::updateBestChain(int unique_index)
863+
{
864+
std::cout<<"updateBestChain"<<std::endl;
865+
M_result.clear();
866+
M_best_evaluation = -std::numeric_limits< double >::max();
867+
868+
dlog.addText( Logger::ACTION_CHAIN,
869+
"updateBestChain: unique_index=%d", unique_index );
870+
871+
std::cout<<"updateBestChain: unique_index="<<unique_index<<std::endl;
872+
while (unique_index != -1){
873+
if (M_all_results.find(unique_index) == M_all_results.end())
874+
{
875+
std::cout<<"updateBestChain: not found"<<std::endl;
876+
return;
877+
}
878+
auto result = M_all_results.at(unique_index);
879+
auto action_state_pair = result.first;
880+
auto eval = result.second;
881+
if (M_best_evaluation == -std::numeric_limits< double >::max())
882+
{
883+
M_best_evaluation = eval;
884+
}
885+
// push action state pair to front of the vector M_result
886+
std::cout<<"updateBestChain: "<<unique_index<<" "<<action_state_pair->action().description()<<" parrentIndex="<<action_state_pair->action().parentIndex()<<std::endl;
887+
M_result.insert(M_result.begin(), *action_state_pair);
888+
unique_index = action_state_pair->action().parentIndex();
889+
}
890+
891+
for (size_t i = 0; i < M_result.size(); ++i)
892+
{
893+
dlog.addText( Logger::ACTION_CHAIN,
894+
"updateBestChain: %d: %s",
895+
i, M_result[i].action().description() );
896+
std::cout<<"updateBestChain: "<<i<<": "<<M_result[i].action().description()<<std::endl;
897+
}
898+
}

src/player/planner/action_chain_graph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class ActionChainGraph {
119119
return M_result;
120120
};
121121

122+
void updateBestChain(int unique_index);
123+
122124
const CooperativeAction & getFirstAction() const
123125
{
124126
return (*(M_result.begin())).action();

src/player/planner/action_chain_holder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,12 @@ ActionChainHolder::graph() const
146146
{
147147
return *M_graph;
148148
}
149+
150+
/*-------------------------------------------------------------------*/
151+
/*!
152+
153+
*/
154+
void ActionChainHolder::updateBestChain(int unique_index)
155+
{
156+
M_graph->updateBestChain(unique_index);
157+
}

src/player/planner/action_chain_holder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class ActionChainHolder {
8181

8282
void update( const rcsc::WorldModel & wm );
8383

84+
void updateBestChain(int unique_index);
85+
8486
const ActionChainGraph & graph() const;
8587
};
8688

src/player/planner/bhv_normal_dribble.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -197,34 +197,34 @@ IntentionNormalDribble::execute( PlayerAgent * agent )
197197
// compare the current queue with other chain action candidates
198198
//
199199

200-
if ( wm.self().isKickable()
201-
&& M_turn_step <= 0 )
202-
{
203-
CooperativeAction::Ptr current_action( new Dribble( wm.self().unum(),
204-
M_target_point,
205-
wm.ball().vel().r(),
206-
0,
207-
M_turn_step,
208-
M_dash_step,
209-
"queuedDribble" ) );
210-
current_action->setIndex( 0 );
211-
current_action->setFirstDashPower( ServerParam::i().maxDashPower() );
212-
213-
ShortDribbleGenerator::instance().setQueuedAction( wm, current_action );
214-
215-
ActionChainHolder::instance().update( wm );
216-
const ActionChainGraph & search_result = ActionChainHolder::i().graph();
217-
const CooperativeAction & first_action = search_result.getFirstAction();
218-
219-
if ( first_action.category() != CooperativeAction::Dribble
220-
|| ! first_action.targetPoint().equals( current_action->targetPoint() ) )
221-
{
222-
agent->debugClient().addMessage( "CancelDribbleQ" );
223-
dlog.addText( Logger::DRIBBLE,
224-
__FILE__": (intention:execute) cancel. select other action." );
225-
return false;
226-
}
227-
}
200+
// if ( wm.self().isKickable()
201+
// && M_turn_step <= 0 )
202+
// {
203+
// CooperativeAction::Ptr current_action( new Dribble( wm.self().unum(),
204+
// M_target_point,
205+
// wm.ball().vel().r(),
206+
// 0,
207+
// M_turn_step,
208+
// M_dash_step,
209+
// "queuedDribble" ) );
210+
// current_action->setIndex( 0 );
211+
// current_action->setFirstDashPower( ServerParam::i().maxDashPower() );
212+
213+
// ShortDribbleGenerator::instance().setQueuedAction( wm, current_action );
214+
215+
// ActionChainHolder::instance().update( wm );
216+
// const ActionChainGraph & search_result = ActionChainHolder::i().graph();
217+
// const CooperativeAction & first_action = search_result.getFirstAction();
218+
219+
// if ( first_action.category() != CooperativeAction::Dribble
220+
// || ! first_action.targetPoint().equals( current_action->targetPoint() ) )
221+
// {
222+
// agent->debugClient().addMessage( "CancelDribbleQ" );
223+
// dlog.addText( Logger::DRIBBLE,
224+
// __FILE__": (intention:execute) cancel. select other action." );
225+
// return false;
226+
// }
227+
// }
228228

229229
//
230230
//

src/player/planner/bhv_planned_action.cpp

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include <rcsc/common/server_param.h>
5858
#include <rcsc/common/logger.h>
5959

60-
// #define DEBUG_PLANNED_ACTION
6160
using namespace rcsc;
6261

6362
namespace {
@@ -203,21 +202,6 @@ Bhv_PlannedAction::Bhv_PlannedAction()
203202
*/
204203
bool
205204
Bhv_PlannedAction::execute( PlayerAgent * agent )
206-
{
207-
dlog.addText( Logger::TEAM,
208-
__FILE__": Bhv_PlannedAction" );
209-
210-
const CooperativeAction & first_action = M_chain_graph.getFirstAction();
211-
212-
#ifdef DEBUG_PLANNED_ACTION
213-
std::cout<<"planner execute"<<" i"<<first_action.uniqueIndex()<< " c"<<first_action.category()<<" t"<<first_action.targetPlayerUnum()<<" p"<<first_action.parentIndex()<<std::endl;
214-
#endif
215-
216-
return execute( agent, first_action.uniqueIndex() );
217-
}
218-
219-
bool
220-
Bhv_PlannedAction::execute( PlayerAgent * agent, int unique_index )
221205
{
222206
dlog.addText( Logger::TEAM,
223207
__FILE__": Bhv_PlannedAction" );
@@ -230,30 +214,9 @@ Bhv_PlannedAction::execute( PlayerAgent * agent, int unique_index )
230214
const ServerParam & SP = ServerParam::i();
231215
const WorldModel & wm = agent->world();
232216

233-
if ( M_chain_graph.getAllResults().find( unique_index ) == M_chain_graph.getAllResults().end() )
234-
{
235-
#ifdef DEBUG_PLANNED_ACTION
236-
std::cout<<"Bhv_PlannedAction: invalid index"<<std::endl;
237-
#endif
238-
dlog.addText( Logger::TEAM,
239-
__FILE__" (Bhv_PlannedAction) invalid index" );
240-
return false;
241-
}
242-
243-
const CooperativeAction & first_action = M_chain_graph.getAllResults().at( unique_index ).first->action();
244-
#ifdef DEBUG_PLANNED_ACTION
245-
std::cout<<"planner execute"<<" i"<<first_action.uniqueIndex()<< " c"<<first_action.category()<<" t"<<first_action.targetPlayerUnum()<<" p"<<first_action.parentIndex()<<std::endl;
246-
#endif
217+
const CooperativeAction & first_action = M_chain_graph.getFirstAction();
247218

248-
if ( first_action.parentIndex() != -1 )
249-
{
250-
#ifdef DEBUG_PLANNED_ACTION
251-
std::cout<<"Bhv_PlannedAction: not root action"<<std::endl;
252-
#endif
253-
dlog.addText( Logger::TEAM,
254-
__FILE__" (Bhv_PlannedAction) not root action" );
255-
return false;
256-
}
219+
// std::cout<<"first action:"<<first_action.category()<<" index:"<<first_action.uniqueIndex()<<std::endl;
257220

258221
// ActionChainGraph::debug_send_chain( agent, M_chain_graph.getAllChain() );
259222

src/thrift-client/thrift_client_player.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,9 @@ bool ThriftClientPlayer::GetBestPlannerAction()
776776
}
777777
auto agent = M_agent;
778778

779+
ActionChainHolder::instance().updateBestChain(best_action.index);
779780

780-
781-
if (Bhv_PlannedAction().execute(agent, best_action.index))
781+
if (Bhv_PlannedAction().execute(agent))
782782
{
783783
#ifdef DEBUG_CLIENT_PLAYER
784784
std::cout << "PlannedAction = "<< best_action.index << std::endl;

0 commit comments

Comments
 (0)