@@ -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+ }
0 commit comments