Ejemplo n.º 1
0
void CAgentLogger::newEpisode()
{
	if (currentEpisode != NULL)
	{
		if (currentEpisode->getNumSteps() > 0)
		{
			if (file != NULL)
			{
				currentEpisode->saveBIN(file);
				fflush(file);
			}	
			episodes->push_back(currentEpisode);
			currentEpisode = new CEpisode(getStateProperties(), getActions(), getStateModifiers());
		}
	}
	else
	{
		currentEpisode = new CEpisode(getStateProperties(), getActions(), getStateModifiers());
	}
	
	if (holdMemory > 0 && (int)episodes->size() > holdMemory)
	{
		CEpisode *firstEpisode = *episodes->begin();
		episodes->pop_front();
		delete firstEpisode;
	}
}
Ejemplo n.º 2
0
BOOL WINAPI DllMain(HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{

    conditionsInfos = getConditionInfos();
    actionsInfos = getActionInfos();
    expressionsInfos = getExpressionInfos();

    ConditionJumps = getConditions();
    ActionJumps = getActions();
    ExpressionJumps = getExpressions();

    switch (dwReason) {
    // DLL is attaching to the address space of the current process.
    case DLL_PROCESS_ATTACH:

        hInstLib = hDLL; // Store HINSTANCE
        break;

    // A new thread is being created in the current process.
    case DLL_THREAD_ATTACH:
        break;

    // A thread is exiting cleanly.
    case DLL_THREAD_DETACH:
        break;

    // The calling process is detaching the DLL from its address space.
    case DLL_PROCESS_DETACH:
        break;
    }

    return TRUE;
}
Ejemplo n.º 3
0
void CAgentLogger::loadBIN(FILE *stream, std::list<CStateModifier *> *modifiers, int numEpisodes)
{
	int nEpisodes = numEpisodes;

	if (holdMemory >= 0 && holdMemory < numEpisodes)
	{
		holdMemory = numEpisodes;
	}
	
	std::list<CStateModifier *> *loadModifiers = modifiers;
	if (loadModifiers == NULL)
	{
		loadModifiers = getStateModifiers();
	}

	while (feof(stream) == 0 && (nEpisodes > 0 || nEpisodes < 0))
	{
		CEpisode  *tmp = new CEpisode(CEpisodeHistory::getStateProperties(), getActions(), loadModifiers);
		tmp->loadBIN(stream);

		if (tmp->getNumSteps() > 0)
		{
			episodes->push_back(tmp);
		}
		else
		{
			delete tmp;
		}

		nEpisodes --;
	}
	newEpisode();
}
Ejemplo n.º 4
0
	void Menu::onAboutToShowSlot()
	{
		if (actions_.empty()){
			actions_ = getActions();
			for_each(actions_.begin(), actions_.end(), 
				bind(&Menu::add, this, _1));
		}
	}
Ejemplo n.º 5
0
Juff::ActionList PythonPlugin::mainMenuActions(Juff::MenuID id) const {
	Juff::ActionList list;
	if ( Juff::MenuTools == id ) {
		Juff::ActionList actions = getActions();
		list << actions;
//		list << act_;
	}
	return list;
}
Ejemplo n.º 6
0
int Sound::load(GFFFile &gff, GFFFile::Struct &top)
{
	std::string tlabels[] =
		{"Active", "Continuous", "Random", "RandomPosition", "Looping",
		 "Positional", "GeneratedType", "Priority", "Times", "Volume",
		 "VolumeVrtn", "PaletteID", "Hours", "Interval", "IntervalVrtn",
		 "ObjectId", "Elevation", "MaxDistance", "MinDistance", "XPosition",
		 "YPosition", "ZPosition", "PitchVariation", "RandomRangeX",
		 "RandomRangeY", "Tag", "Comment", "TemplateResRef", "LocName",
		 "Sounds", "ActionList", "VarTable"};
	std::vector<uint32> n;

	if(gff.getIdxByLabel(tlabels, sizeof(tlabels)/sizeof(std::string),
				top, n, aderrstr))
		return ERR(gff);
	if(n[0] != NOTFOUND) active = (bool) top.values[n[0]];
	if(n[1] != NOTFOUND) continuous = (bool) top.values[n[1]];
	if(n[2] != NOTFOUND) random = (bool) top.values[n[2]];
	if(n[3] != NOTFOUND) randomposition = (bool) top.values[n[3]];
	if(n[4] != NOTFOUND) looping = (bool) top.values[n[4]];
	if(n[5] != NOTFOUND) positional = (bool) top.values[n[5]];
	if(n[6] != NOTFOUND) generatedtype = (bool) top.values[n[6]];
	if(n[7] != NOTFOUND) priority = top.values[n[7]];
	if(n[8] != NOTFOUND) times = top.values[n[8]];
	if(n[9] != NOTFOUND) volume = top.values[n[9]];
	if(n[10] != NOTFOUND) volumevrtn = top.values[n[10]];
	if(n[11] != NOTFOUND) paletteid = top.values[n[11]];
	if(n[12] != NOTFOUND) hours = top.values[n[12]];
	if(n[13] != NOTFOUND) interval = top.values[n[13]];
	if(n[14] != NOTFOUND) intervalvrtn = top.values[n[14]];
	if(n[15] != NOTFOUND) objectid = top.values[n[15]];
	if(n[16] != NOTFOUND) elevation = *((float32 *) &top.values[n[16]]);
	if(n[17] != NOTFOUND) maxdistance = *((float32 *) &top.values[n[17]]);
	if(n[18] != NOTFOUND) mindistance = *((float32 *) &top.values[n[18]]);
	if(n[19] != NOTFOUND) x = *((float32 *) &top.values[n[19]]);
	if(n[20] != NOTFOUND) y = *((float32 *) &top.values[n[20]]);
	if(n[21] != NOTFOUND) z = *((float32 *) &top.values[n[21]]);
	if(n[22] != NOTFOUND) pitchvariation = *((float32 *) &top.values[n[22]]);
	if(n[23] != NOTFOUND) randomrangex = *((float32 *) &top.values[n[23]]);
	if(n[24] != NOTFOUND) randomrangey = *((float32 *) &top.values[n[24]]);
	if(n[25] != NOTFOUND)
		if(gff.getExoString(n[25], top, tag)) return ERR(gff);
	if(n[26] != NOTFOUND)
		if(gff.getExoString(n[26], top, comment)) return ERR(gff);
	if(n[27] != NOTFOUND)
		if(gff.getResRef(n[27], top, templateresref)) return ERR(gff);
	if(n[28] != NOTFOUND)
		if(gff.getExoLocString(n[28], top, name)) return ERR(gff);
	if(n[29] != NOTFOUND) if(getSounds(gff, n[29], top)) return errcode;
	if(n[30] != NOTFOUND) if(getActions(gff, n[29], top)) return errcode;
	if(n[31] != NOTFOUND)
		if(variables.load(gff, n[32], top)) return ERR(variables);
	checkRanges();

	return errcode = 0;
}
Ejemplo n.º 7
0
void CAgentLogger::init()
{
	file = NULL;
	episodes = new std::list<CEpisode *>();

	currentEpisode = new CEpisode(getStateProperties(), getActions());

    	holdMemory = -1;
    
   	loadFileName[0] = '\0';

	loadModifiers = NULL;
}
Ejemplo n.º 8
0
	type_result ForEach::execute()
	{
		NEModuleSelector& sel = getTargetSelector();
		type_int& count = getCount();
		NEModuleCodeSet& actions = getActions();

		while(NEModule* itr = &sel.getModule())
		{
			count++;
			actions.execute();
		}

		return RESULT_SUCCESS;
	}
void MVCondottiereState::update(shared_ptr<MVPlayer> player, int message)
{
	vector<MVEnum::Action> actions = getActions();
	if (message >= 0 && message < actions.size())
	{
		switch (actions[message])
		{
		case MVEnum::DESTROY_BUILDING:
			DestroyBuilding(player);
			break;
		default:
			MVClaimGoldCharacterState::update(player, message);
			return;
		}
	}
}
Ejemplo n.º 10
0
double CFeatureRewardModel::getReward(int oldState, CAction *action, int newState)
{
	int actionIndex = getActions()->getIndex(action);
	double transVisits = getTransitionVisits(oldState, actionIndex, newState);

	//assert(visitSparse->getFaktor(oldState, actionIndex, newState) > 0);


	if (transVisits > 0)
	{
		return rewardTable->get(actionIndex, oldState)->getValue(newState) / transVisits;
	}
	else
	{
		return 0.0;
	}
}
Ejemplo n.º 11
0
void CAgentLogger::loadData(FILE *stream, int numEpisodes)
{
	int nEpisodes = numEpisodes;
	int buf;

	if (holdMemory >= 0 && holdMemory < numEpisodes)
	{
		holdMemory = numEpisodes;
	}

	while (feof(stream) == 0 && (nEpisodes > 0 || nEpisodes < 0))
	{
		CEpisode  *tmp = new CEpisode(getStateProperties(), getActions(), getStateModifiers());
		fscanf(stream, "\nEpisode: %d\n", &buf);
		tmp->loadData(stream);

		episodes->push_back(tmp);

		nEpisodes --;
	}
	
	newEpisode();
}
Ejemplo n.º 12
0
	void IToolBar::fills()
	{
		vector<IAction*> actions = getActions();
		for_each(actions.begin(), actions.end(), bind(&IToolBar::add
			, this, _1));
	}
Ejemplo n.º 13
0
void Controller::handle(const std::vector<std::string>& parameters, Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
	_parameters = parameters;
	_request = &request;
	_response = &response;

	if ( _parameters.size() > 0 )
	{
		_action = _parameters.front();
		_parameters.erase(_parameters.begin());
	}
	else
	{
		setResponseStatus(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST, "Invalid URI parameters");
		return;
	}

	for(std::vector<std::string>::iterator it = _parameters.begin(); it != _parameters.end(); ++it)
	{
		int pos = it->find_first_of(':');
		if ( pos != std::string::npos )
		{
			std::string name = it->substr(0, pos);
			std::string value = it->substr(pos+1);
			_namedParameters[name] = value;
		}
	}

	std::string contentType = request.getContentType();
	if ( contentType == "application/json" )
	{
		Poco::JSON::Parser parser;
		try
		{
			Poco::Dynamic::Var json = parser.parse(request.stream());
			if ( ! json.isEmpty() && json.type() == typeid(Poco::JSON::Object::Ptr) )
			{
				_data->set("filter", json.extract<Poco::JSON::Object::Ptr>());
			}
		}
		catch(Poco::JSON::JSONException& jsone)
		{
			// Make sure everything is read, otherwise this can result
			// in Bad Request error in the next call.
			Poco::NullOutputStream nos;
			Poco::StreamCopier::copyStream(request.stream(), nos);

			setResponseStatus(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST, "JSON error occurred: " + jsone.displayText());
			return;
		}
	}
	else
	{
		_form.load(request, request.stream(), *this);
	}

	// Make sure everything is read, otherwise this can result
	// in Bad Request error in the next call.
	Poco::NullOutputStream nos;
	Poco::StreamCopier::copyStream(request.stream(), nos);

	beforeAction();

	if ( response.getStatus() != Poco::Net::HTTPResponse::HTTP_OK
		|| _data->has("error") )
	{
		//TODO: return error template file or json error
	}

	const ActionMap& actions = getActions();
	ActionMap::const_iterator it = actions.find(_action);
	if ( it == actions.end() )
	{
		setResponseStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND, "Invalid action '" + _action + "' specified.");
		return;
	}

	ActionFn action = it->second;
	(this->*action)();

	afterAction();
}
Ejemplo n.º 14
0
DAction* MCar::getInitialAction() const {
    return new DAction(getActions(), 1);
}
Ejemplo n.º 15
0
DAction* GridWorld::getInitialAction() const {
    return new DAction(getActions(), 0);
}
Ejemplo n.º 16
0
void CFeatureRewardModel::nextStep(CStateCollection *oldState, CAction *action, double reward, CStateCollection *newState)
{
	CFeatureMap *featMap;

	CState *oldS = oldState->getState(properties);
	CState *newS = newState->getState(properties);

	double oldreward = 0.0;
	double visits = 0.0;

	int actionIndex = getActions()->getIndex(action);
	
	int type = oldS->getStateProperties()->getType() & (DISCRETESTATE | FEATURESTATE);
	switch (type)
	{
		case FEATURESTATE:
		{
			for (unsigned int oldIndex = 0; oldIndex < oldS->getNumDiscreteStates(); oldIndex++)
			{
				int oldFeature = oldS->getDiscreteState(oldIndex);
				featMap = rewardTable->get(actionIndex, oldFeature);

				for (unsigned int newIndex = 0; newIndex < newS->getNumDiscreteStates(); newIndex++)
				{
					int newFeature = newS->getDiscreteState(newIndex);

					oldreward = featMap->getValue(newFeature);
				

					(*featMap)[newFeature] = oldreward + reward * newS->getContinuousState(newIndex) * oldS->getContinuousState(oldIndex);
					
					if (!bExternVisitSparse)
					{
						visits = visitTable->get(actionIndex, oldFeature)->getValue(newFeature);
					
						(*visitTable->get(actionIndex, oldFeature))[newFeature] = visits + newS->getContinuousState(newIndex) * oldS->getContinuousState(oldIndex);;
					}
				}
			}
			break;
		}
		case DISCRETESTATE:
		default: 
		{
			featMap = rewardTable->get(actionIndex, oldS->getDiscreteStateNumber());

			oldreward = featMap->getValue(newS->getDiscreteStateNumber());
		
			int feata = oldS->getDiscreteStateNumber();
			int featb = newS->getDiscreteStateNumber();

			(*featMap)[featb] = oldreward + reward;
			
			if (!bExternVisitSparse)
			{
				visits = visitTable->get(actionIndex, feata)->getValue(featb);
			
				(*visitTable->get(actionIndex, feata))[featb] = visits + 1.0;
			}
			break;
		}
	}
}