//this function extends a previous policy jpolPrevTs for ts-1 with the behavior specified by the policy of the BayesianGame for time step ts (jpolBG).
PartialJointPolicyDiscretePure* 
BayesianGameForDecPOMDPStage::ConstructExtendedPolicy(
        PartialJointPolicyDiscretePure& jpolPrevTs, 
        JointPolicyDiscretePure& jpolBG, 
        vector<size_t>& nrOHts, 
        vector<Index>& firstOHtsI
        )
{
    //check policy types
    if(jpolPrevTs.GetIndexDomainCategory() != PolicyGlobals::OHIST_INDEX)
        throw E("BayesianGameForDecPOMDPStage::ConstructExtendedPolicy --- jpolPrevTs.GetIndexDomainCategory() != PolicyGlobals::OHIST_INDEX ");
    if(jpolBG.GetIndexDomainCategory() != PolicyGlobals::TYPE_INDEX)
        throw E("BayesianGameForDecPOMDPStage::ConstructExtendedPolicy --- jpolPrevTs.GetIndexDomainCategory() != PolicyGlobals::TYPE_INDEX ");
    //construct a policy for the DecPOMDP: 
    //a copy of jpolPrevTs with extended to this time step (ts) by 
    //jpolBG
    PartialJointPolicyDiscretePure* jpolTs = new 
        PartialJointPolicyPureVector(jpolPrevTs);
    jpolTs->SetDepth( jpolTs->GetDepth()+1 );
    for(Index agentI=0; agentI < GetNrAgents(); agentI++)
    {
        for(Index type = 0; type < nrOHts[agentI]; type++)
        {
            Index ohI = type + firstOHtsI[agentI];
            jpolTs->SetAction(agentI, ohI, 
                    jpolBG.GetActionIndex(agentI, type) );
        }         
    }
    return(jpolTs);
}
void PlanningUnitFactoredDecPOMDPDiscrete::
ComputeFSAOHDist(
        FactoredStateAOHDistribution* fsaoh, 
        const PartialJointPolicyDiscretePure& pJPol) const
{
    Index depth = pJPol.GetDepth();
    //cout << "computing factored FSAOHDist for policy of depth"<< depth<<endl;
    fsaoh->InitializeFromISD( GetFDPOMDPD()->GetFactoredISD() );
    fsaoh->SanityCheck();
    Index lastStage;
    if(depth > 0)
        //depth 1 specifies action for t=0 -> compute FSAOH for t=1
        lastStage = depth; 
    else
        return;

    //cerr<<"starting updates from t=0 to t<"<<lastStage<<endl;
    for(Index t=0 ; t < lastStage; t++)
        fsaoh->Update(pJPol);
}