src/cellar.cpp
// PGS Rollout policy
// Computes PGS only for non-checking actions
PGS Rollout policy
Computes PGS only for non-checking actions
PGS Rollout policy Computes PGS only for non - checking actions
void CELLAR::GeneratePGS(const STATE& state, const HISTORY& history,
    vector<int>& legal, const STATUS& status) const
{
	static vector<int> acts;
	acts.clear();
	STATE * newstate;
	STATE * oldstate = Copy(state);
	PGSLegal(state, history, acts, status);
	int numLegal = acts.size();
	double pgs_values[numLegal]; 
	double pgs_state = PGS(*oldstate);	
	int max_p = -1;
	double max_v = -Infinity;	
	int observation;
	double reward;
	for(unsigned int i=0; i<numLegal; i++){		
		newstate = Copy(state);
		StepNormal(*newstate, acts[i], observation, reward); 
		pgs_values[i] = PGS_RO(*oldstate, *newstate, acts[i], pgs_state); 
		FreeState(newstate);		
	}
	FreeState(oldstate);
	max_p = std::distance(pgs_values, max_element(pgs_values, pgs_values+numLegal));
	max_v = pgs_values[max_p];
	assert(max_p > -1);
	legal.push_back(acts[max_p]); 
	for(int i=0; i<numLegal; i++){
		if(i != max_p && pgs_values[i] == max_v)
            legal.push_back(acts[i]);
	}
}
void CELLAR :: GeneratePGS ( const STATE & state , const HISTORY & history , vector < int > & legal , const STATUS & status ) const { static vector < int > acts ; acts . clear ( ) ; STATE * newstate ; STATE * oldstate = Copy ( state ) ; PGSLegal ( state , history , acts , status ) ; int numLegal = acts . size ( ) ; double pgs_values [ numLegal ] ; double pgs_state = PGS ( * oldstate ) ; int max_p = -1 ; double max_v = - Infinity ; int observation ; double reward ; for ( unsigned int i = 0 ; i < numLegal ; i ++ ) { newstate = Copy ( state ) ; StepNormal ( * newstate , acts [ i ] , observation , reward ) ; pgs_values [ i ] = PGS_RO ( * oldstate , * newstate , acts [ i ] , pgs_state ) ; FreeState ( newstate ) ; } FreeState ( oldstate ) ; max_p = std :: distance ( pgs_values , max_element ( pgs_values , pgs_values + numLegal ) ) ; max_v = pgs_values [ max_p ] ; assert ( max_p > -1 ) ; legal . push_back ( acts [ max_p ] ) ; for ( int i = 0 ; i < numLegal ; i ++ ) { if ( i != max_p && pgs_values [ i ] == max_v ) legal . push_back ( acts [ i ] ) ; } }
PGS Rollout policy
Computes PGS only for non-checking actions
PGS Rollout policy Computes PGS only for non - checking actions
//pgs_values[i] <-- legalMove[i] //cout << "Generating PGS values..." << endl; //cout << "Found " << numLegal << " legal actions." << endl; //Simulate transition with action a // Using regular PGS (slow) //pgs_values[i] = PGS(*newstate); // Adding only PGS differences (fast) //add differences //Add best action to return vector // Add other maxima