src/cellar.cpp
/*
    Uniformly random (legal) actions
*/
Uniformly random (legal) actions
Uniformly random ( legal ) actions
void CELLAR::GenerateLegal(const STATE& state, const HISTORY& history,
    vector<int>& legal, const STATUS& status) const
{
    const CELLAR_STATE& cellarstate =
        safe_cast<const CELLAR_STATE&>(state);
	 COORD pos = COORD(cellarstate.AgentPos.X, cellarstate.AgentPos.Y);
	 COORD posN = COORD(cellarstate.AgentPos.X, cellarstate.AgentPos.Y+1);
	 COORD posS = COORD(cellarstate.AgentPos.X, cellarstate.AgentPos.Y-1);
	 COORD posW = COORD(cellarstate.AgentPos.X-1, cellarstate.AgentPos.Y);
	 COORD posE = COORD(cellarstate.AgentPos.X+1, cellarstate.AgentPos.Y);		
    if (cellarstate.AgentPos.Y + 1 < Size && FreeTile(cellarstate, posN))
        legal.push_back(COORD::E_NORTH);
	 if(FreeTile(cellarstate, posE))
		  legal.push_back(COORD::E_EAST);
    if (cellarstate.AgentPos.Y - 1 >= 0 && FreeTile(cellarstate, posS))
        legal.push_back(COORD::E_SOUTH);
    if (cellarstate.AgentPos.X - 1 >= 0 && FreeTile(cellarstate, posW))
        legal.push_back(COORD::E_WEST);
    int bottle = Grid(cellarstate.AgentPos);
    if (bottle >= 0 && bottle < NumBottles && !cellarstate.Bottles[bottle].Collected){
        legal.push_back(E_SAMPLE + bottle);
	 }
    for (bottle = 0; bottle < NumBottles; ++bottle)
        if (!cellarstate.Bottles[bottle].Collected)
            legal.push_back(E_BOTTLECHECK + bottle);
	 for (int obj = 0; obj < NumObjects; ++obj)
      legal.push_back(E_OBJCHECK + obj);
	bool objN = false; 
	bool objE = false; 
	bool objS = false; 
    bool objW = false; 
	if(Grid.Inside(posN) && Grid(posN) >= 0 && Grid(posN) < NumBottles){
		legal.push_back(E_BPUSHNORTH + Grid(posN));
	}
	if(Grid.Inside(posS) && Grid(posS) >= 0 && Grid(posS) < NumBottles){
		legal.push_back(E_BPUSHSOUTH + Grid(posS));
	}
	if(Grid.Inside(posE) && Grid(posE) >= 0 && Grid(posE) < NumBottles){
		legal.push_back(E_BPUSHEAST + Grid(posE));
	}
	if(Grid.Inside(posW) && Grid(posW) >= 0 && Grid(posW) < NumBottles){
		legal.push_back(E_BPUSHWEST + Grid(posW));
	}	 
	int numObjN, numObjS, numObjE, numObjW;
	bool objsFound = false; 
	for(int i=0; i<cellarstate.Objects.size() && !objsFound; i++){
	 	if(cellarstate.Objects[i].active){
			if (cellarstate.Objects[i].ObjPos == posN) {
				objN = true;
				numObjN = i;
			}
			if (cellarstate.Objects[i].ObjPos == posE) {
				objE = true;
				numObjE = i;
			}
			if (cellarstate.Objects[i].ObjPos == posS) {
				objS = true;
				numObjS = i;
			}
			if (cellarstate.Objects[i].ObjPos == posW) {
				objW = true;
				numObjW = i;
			}
			objsFound = objN && objE && objS && objW;
		}
	}
	if (cellarstate.AgentPos.Y + 1 < Size && objN)
        legal.push_back(E_PUSHNORTH + numObjN);
	if (cellarstate.AgentPos.X + 1 < Size && objE)
		legal.push_back(E_PUSHEAST + numObjE);
    if (cellarstate.AgentPos.Y - 1 >= 0 && objS)
        legal.push_back(E_PUSHSOUTH + numObjS);
    if (cellarstate.AgentPos.X - 1 >= 0 && objW)
        legal.push_back(E_PUSHWEST + numObjW);
}
void CELLAR :: GenerateLegal ( const STATE & state , const HISTORY & history , vector < int > & legal , const STATUS & status ) const { const CELLAR_STATE & cellarstate = safe_cast < const CELLAR_STATE & > ( state ) ; COORD pos = COORD ( cellarstate . AgentPos . X , cellarstate . AgentPos . Y ) ; COORD posN = COORD ( cellarstate . AgentPos . X , cellarstate . AgentPos . Y + 1 ) ; COORD posS = COORD ( cellarstate . AgentPos . X , cellarstate . AgentPos . Y - 1 ) ; COORD posW = COORD ( cellarstate . AgentPos . X - 1 , cellarstate . AgentPos . Y ) ; COORD posE = COORD ( cellarstate . AgentPos . X + 1 , cellarstate . AgentPos . Y ) ; if ( cellarstate . AgentPos . Y + 1 < Size && FreeTile ( cellarstate , posN ) ) legal . push_back ( COORD :: E_NORTH ) ; if ( FreeTile ( cellarstate , posE ) ) legal . push_back ( COORD :: E_EAST ) ; if ( cellarstate . AgentPos . Y - 1 >= 0 && FreeTile ( cellarstate , posS ) ) legal . push_back ( COORD :: E_SOUTH ) ; if ( cellarstate . AgentPos . X - 1 >= 0 && FreeTile ( cellarstate , posW ) ) legal . push_back ( COORD :: E_WEST ) ; int bottle = Grid ( cellarstate . AgentPos ) ; if ( bottle >= 0 && bottle < NumBottles && ! cellarstate . Bottles [ bottle ] . Collected ) { legal . push_back ( E_SAMPLE + bottle ) ; } for ( bottle = 0 ; bottle < NumBottles ; ++ bottle ) if ( ! cellarstate . Bottles [ bottle ] . Collected ) legal . push_back ( E_BOTTLECHECK + bottle ) ; for ( int obj = 0 ; obj < NumObjects ; ++ obj ) legal . push_back ( E_OBJCHECK + obj ) ; bool objN = false ; bool objE = false ; bool objS = false ; bool objW = false ; if ( Grid . Inside ( posN ) && Grid ( posN ) >= 0 && Grid ( posN ) < NumBottles ) { legal . push_back ( E_BPUSHNORTH + Grid ( posN ) ) ; } if ( Grid . Inside ( posS ) && Grid ( posS ) >= 0 && Grid ( posS ) < NumBottles ) { legal . push_back ( E_BPUSHSOUTH + Grid ( posS ) ) ; } if ( Grid . Inside ( posE ) && Grid ( posE ) >= 0 && Grid ( posE ) < NumBottles ) { legal . push_back ( E_BPUSHEAST + Grid ( posE ) ) ; } if ( Grid . Inside ( posW ) && Grid ( posW ) >= 0 && Grid ( posW ) < NumBottles ) { legal . push_back ( E_BPUSHWEST + Grid ( posW ) ) ; } int numObjN , numObjS , numObjE , numObjW ; bool objsFound = false ; for ( int i = 0 ; i < cellarstate . Objects . size ( ) && ! objsFound ; i ++ ) { if ( cellarstate . Objects [ i ] . active ) { if ( cellarstate . Objects [ i ] . ObjPos == posN ) { objN = true ; numObjN = i ; } if ( cellarstate . Objects [ i ] . ObjPos == posE ) { objE = true ; numObjE = i ; } if ( cellarstate . Objects [ i ] . ObjPos == posS ) { objS = true ; numObjS = i ; } if ( cellarstate . Objects [ i ] . ObjPos == posW ) { objW = true ; numObjW = i ; } objsFound = objN && objE && objS && objW ; } } if ( cellarstate . AgentPos . Y + 1 < Size && objN ) legal . push_back ( E_PUSHNORTH + numObjN ) ; if ( cellarstate . AgentPos . X + 1 < Size && objE ) legal . push_back ( E_PUSHEAST + numObjE ) ; if ( cellarstate . AgentPos . Y - 1 >= 0 && objS ) legal . push_back ( E_PUSHSOUTH + numObjS ) ; if ( cellarstate . AgentPos . X - 1 >= 0 && objW ) legal . push_back ( E_PUSHWEST + numObjW ) ; }
Uniformly random (legal) actions
Uniformly random ( legal ) actions
//Move is only possible when there are no obstacles // If standing over a non sampled bottle, allow sample // 'Check' possible for non sampled bottles // 'Check' possible for all other objects, always //Push actions for adjacent objects	 		  		   //(Grid.Inside(posN) && Grid(posN) >= 0)? Grid(posN) < NumBottles : false; //(Grid.Inside(posE) && Grid(posE) >= 0)? Grid(posE) < NumBottles : false; //(Grid.Inside(posS) && Grid(posS) >= 0)? Grid(posS) < NumBottles : false; //(Grid.Inside(posW) && Grid(posW) >= 0)? Grid(posW) < NumBottles : false; //objN && objE && objS && objW;