Skip to content

Commit 131506b

Browse files
authored
Merge pull request #45 from CLSFramework/fix-server-side
Fix-server-side
2 parents 78a5a91 + 581140e commit 131506b

16 files changed

+104
-151
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/actgen_cross.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ ActGen_Cross::generate( std::vector< ActionStatePair > * result,
5959

6060
const std::vector< CooperativeAction::Ptr > & courses = CrossGenerator::instance().courses( wm );
6161

62-
for (auto & course : courses)
63-
{
64-
if (path.empty())
65-
{
66-
course->setParentIndex(-1);
67-
}
68-
else
69-
{
70-
course->setParentIndex(( *( path.rbegin() ) ).action().uniqueIndex());
71-
}
72-
}
7362

7463
//
7564
// add pass course candidates

src/player/planner/actgen_direct_pass.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,6 @@ ActGen_DirectPass::generate( std::vector< ActionStatePair > * result,
305305
kick_step,
306306
false,
307307
"actgenDirect" ) );
308-
if (path.empty())
309-
{
310-
action->setParentIndex(-1);
311-
}
312-
else
313-
{
314-
action->setParentIndex(( *( path.rbegin() ) ).action().uniqueIndex());
315-
}
316308
++s_action_count;
317309
++generated_count;
318310
action->setIndex( s_action_count );

src/player/planner/actgen_self_pass.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ ActGen_SelfPass::generate( std::vector< ActionStatePair > * result,
6969
const std::vector< CooperativeAction::Ptr > &
7070
cont = SelfPassGenerator::instance().courses( wm );
7171

72-
for (auto & course : cont)
73-
{
74-
if (path.empty())
75-
{
76-
course->setParentIndex(-1);
77-
}
78-
else
79-
{
80-
course->setParentIndex(( *( path.rbegin() ) ).action().uniqueIndex());
81-
}
82-
}
8372
//
8473
// add dribble candidates
8574
//

src/player/planner/actgen_shoot.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,6 @@ ActGen_Shoot::generate( std::vector< ActionStatePair > * result,
108108
shoot_spend_time,
109109
1,
110110
"shoot" ) );
111-
if (path.empty())
112-
{
113-
action->setParentIndex(-1);
114-
}
115-
else
116-
{
117-
action->setParentIndex(( *( path.rbegin() ) ).action().uniqueIndex());
118-
}
119111

120112
result->push_back( ActionStatePair( action, result_state ) );
121113
}

src/player/planner/actgen_short_dribble.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ ActGen_ShortDribble::generate( std::vector< ActionStatePair > * result,
7070
const std::vector< CooperativeAction::Ptr > &
7171
cont = ShortDribbleGenerator::instance().courses( wm );
7272

73-
for (auto & course : cont)
74-
{
75-
if (path.empty())
76-
{
77-
course->setParentIndex(-1);
78-
}
79-
else
80-
{
81-
course->setParentIndex(( *( path.rbegin() ) ).action().uniqueIndex());
82-
}
83-
}
8473
//
8574
// add dribble candidates
8675
//

src/player/planner/actgen_simple_dribble.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,6 @@ ActGen_SimpleDribble::generate( std::vector< ActionStatePair > * result,
191191
holder_reach_step - 2,
192192
"actgenDribble" ) );
193193

194-
if (path.empty())
195-
{
196-
action->setParentIndex(-1);
197-
}
198-
else
199-
{
200-
action->setParentIndex(( *( path.rbegin() ) ).action().uniqueIndex());
201-
}
202194
++s_action_count;
203195
++generated_count;
204196
action->setIndex( s_action_count );

src/player/planner/actgen_strict_check_pass.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ ActGen_StrictCheckPass::generate( std::vector< ActionStatePair > * result,
6262
M_generate_direct_pass,
6363
M_generate_lead_pass,
6464
M_generate_through_pass );
65-
for (auto & course : courses)
66-
{
67-
if (path.empty())
68-
{
69-
course->setParentIndex(-1);
70-
}
71-
else
72-
{
73-
course->setParentIndex(( *( path.rbegin() ) ).action().uniqueIndex());
74-
}
75-
}
7665
//
7766
// add pass course candidates
7867
//

src/player/planner/action_chain_graph.cpp

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ ActionChainGraph::calculateResultBestFirstSearch( const WorldModel & wm,
524524

525525
auto copy_action = std::make_shared<CooperativeAction>(it->action());
526526
auto copy_state = std::make_shared<PredictState>(it->state());
527+
copy_action->setParentIndex(parent_index);
527528
auto new_action_state_pair = std::shared_ptr<ActionStatePair>(new ActionStatePair(copy_action, copy_state));
528529
M_all_results[copy_action->uniqueIndex()] = std::make_pair(new_action_state_pair, ev);
529530

@@ -779,6 +780,7 @@ ActionChainGraph::write_chain_log( const std::string & pre_log_message,
779780
for ( size_t i = 0; i < path.size(); ++i )
780781
{
781782
const CooperativeAction & a = path[i].action();
783+
int unique_index = a.uniqueIndex();
782784
const PredictState * s0;
783785
const PredictState * s1;
784786

@@ -798,16 +800,16 @@ ActionChainGraph::write_chain_log( const std::string & pre_log_message,
798800
case CooperativeAction::Hold:
799801
{
800802
dlog.addText( Logger::ACTION_CHAIN,
801-
"__ %d: hold (%s) t=%d",
802-
i, a.description(), s1->spendTime() );
803+
"__ %d: u%d: hold (%s) t=%d",
804+
i, unique_index, a.description(), s1->spendTime() );
803805
break;
804806
}
805807

806808
case CooperativeAction::Dribble:
807809
{
808810
dlog.addText( Logger::ACTION_CHAIN,
809-
"__ %d: dribble (%s[%d]) t=%d unum=%d target=(%.2f %.2f)",
810-
i, a.description(), a.index(), s1->spendTime(),
811+
"__ %d: u%d: dribble (%s[%d]) t=%d unum=%d target=(%.2f %.2f)",
812+
i, unique_index, a.description(), a.index(), s1->spendTime(),
811813
s0->ballHolderUnum(),
812814
a.targetPoint().x, a.targetPoint().y );
813815
break;
@@ -816,8 +818,8 @@ ActionChainGraph::write_chain_log( const std::string & pre_log_message,
816818
case CooperativeAction::Pass:
817819
{
818820
dlog.addText( Logger::ACTION_CHAIN,
819-
"__ %d: pass (%s[%d]) t=%d from[%d](%.2f %.2f)-to[%d](%.2f %.2f)",
820-
i, a.description(), a.index(), s1->spendTime(),
821+
"__ %d: u%d: pass (%s[%d]) t=%d from[%d](%.2f %.2f)-to[%d](%.2f %.2f)",
822+
i, unique_index, a.description(), a.index(), s1->spendTime(),
821823
s0->ballHolderUnum(),
822824
s0->ball().pos().x, s0->ball().pos().y,
823825
s1->ballHolderUnum(),
@@ -828,8 +830,8 @@ ActionChainGraph::write_chain_log( const std::string & pre_log_message,
828830
case CooperativeAction::Shoot:
829831
{
830832
dlog.addText( Logger::ACTION_CHAIN,
831-
"__ %d: shoot (%s) t=%d unum=%d",
832-
i, a.description(), s1->spendTime(),
833+
"__ %d: u%d: shoot (%s) t=%d unum=%d",
834+
i, unique_index, a.description(), s1->spendTime(),
833835
s0->ballHolderUnum() );
834836

835837
break;
@@ -838,18 +840,61 @@ ActionChainGraph::write_chain_log( const std::string & pre_log_message,
838840
case CooperativeAction::Move:
839841
{
840842
dlog.addText( Logger::ACTION_CHAIN,
841-
"__ %d: move (%s)",
842-
i, a.description(), s1->spendTime() );
843+
"__ %d: u%d: move (%s)",
844+
i, unique_index, a.description(), s1->spendTime() );
843845
break;
844846
}
845847

846848
default:
847849
{
848850
dlog.addText( Logger::ACTION_CHAIN,
849-
"__ %d: ???? (%s)",
850-
i, a.description(), s1->spendTime() );
851+
"__ %d: u%d: ???? (%s)",
852+
i, unique_index, a.description(), s1->spendTime() );
851853
break;
852854
}
853855
}
854856
}
855857
}
858+
859+
/*-------------------------------------------------------------------*/
860+
/*!
861+
862+
*/
863+
void
864+
ActionChainGraph::updateBestChain(int unique_index)
865+
{
866+
std::cout<<"updateBestChain"<<std::endl;
867+
M_result.clear();
868+
M_best_evaluation = -std::numeric_limits< double >::max();
869+
870+
dlog.addText( Logger::ACTION_CHAIN,
871+
"updateBestChain: unique_index=%d", unique_index );
872+
873+
std::cout<<"updateBestChain: unique_index="<<unique_index<<std::endl;
874+
while (unique_index != -1){
875+
if (M_all_results.find(unique_index) == M_all_results.end())
876+
{
877+
std::cout<<"updateBestChain: not found"<<std::endl;
878+
return;
879+
}
880+
auto result = M_all_results.at(unique_index);
881+
auto action_state_pair = result.first;
882+
auto eval = result.second;
883+
if (M_best_evaluation == -std::numeric_limits< double >::max())
884+
{
885+
M_best_evaluation = eval;
886+
}
887+
// push action state pair to front of the vector M_result
888+
std::cout<<"updateBestChain: "<<unique_index<<" "<<action_state_pair->action().description()<<" parrentIndex="<<action_state_pair->action().parentIndex()<<std::endl;
889+
M_result.insert(M_result.begin(), *action_state_pair);
890+
unique_index = action_state_pair->action().parentIndex();
891+
}
892+
893+
for (size_t i = 0; i < M_result.size(); ++i)
894+
{
895+
dlog.addText( Logger::ACTION_CHAIN,
896+
"updateBestChain: %d: %s",
897+
i, M_result[i].action().description() );
898+
std::cout<<"updateBestChain: "<<i<<": "<<M_result[i].action().description()<<std::endl;
899+
}
900+
}

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();

0 commit comments

Comments
 (0)