Esempio n. 1
0
EExecStatus CActionWander::Update(CActor* pActor)
{
	if ((CurrAction.isvalid() && CurrAction->Update(pActor) == Running) ||
		NextActSelectionTime > (float)GameSrv->GetTime())
	{
		return Running;
	}

	return SelectAction(pActor) ? Running : Failure;
}
Esempio n. 2
0
void ActionMenu::ProcessInput()
{
	if (!m_bChoiceLocked && !m_bExpired)
	{
		if (m_numChoices == 2)
		{
			if (InputMgr::Instance().WasPressed(VK_LEFT) && m_activeChoice != 0)
				SelectAction(0);

			else if (InputMgr::Instance().WasPressed(VK_RIGHT) && m_activeChoice != 1)
				SelectAction(1);
		}
		else if (m_numChoices == 4)
		{
			if (InputMgr::Instance().WasPressed(VK_UP) && m_activeChoice != 0)
				SelectAction(0);

			else if (InputMgr::Instance().WasPressed(VK_RIGHT) && m_activeChoice != 1)
				SelectAction(1);

			else if (InputMgr::Instance().WasPressed(VK_DOWN) && m_activeChoice != 2)
				SelectAction(2);

			else if (InputMgr::Instance().WasPressed(VK_LEFT) && m_activeChoice != 3)
				SelectAction(3);
		}

		if (InputMgr::Instance().WasPressed(GEN_A))
			ConfirmAction();

		if (InputMgr::Instance().WasPressed(GEN_B))
			DismissMenu();
	}
}
Esempio n. 3
0
int CAgent::TimeStep(CWorldState* pWorldState)
{
	FilterState(pWorldState,true);	//acquire state again as other agents might have changed it

	if (!IsStateValid()) return -1;

	UpdateQMatrices(pWorldState, false);	//update q matrices from all modules
									//world state is passed as an argument to calculate rewards

	int action= SelectAction();		//greedy, e-greedy, ...

	TakeAction(action,pWorldState); //update world

	FilterState(pWorldState,false);	//acquire state again as other agents might have changed it

	UpdateQMatrices(pWorldState, true);
//	FilterState(pWorldState,false);	//spread new state among all modules

//	if (!IsStateValid()) return -1;

	return action;
}
Esempio n. 4
0
bool CActionWander::Activate(CActor* pActor)
{
	InitialPos.set(pActor->Position.x, pActor->Position.z);
	return SelectAction(pActor);
}
Esempio n. 5
0
File: AI.cpp Progetto: txal/XProject
void RobotAI::Update(int64_t nNowMS)
{
	if (!m_bRun)
	{
		return;
	}
	//if (m_poActor == NULL || m_poActor->GetScene() == NULL || m_poActor->IsDead())
	//{
	//	return;
	//}

	//if (m_poTarget != NULL && (m_poTarget->IsDead() || m_poTarget->GetScene() == NULL))
	//{
	//	m_poTarget = NULL;
	//	m_poAction->SetTarget(m_poTarget);
	//	SetState(eAIS_Idle, GetStateTime(eAIS_Idle), __LINE__);
	//}

	switch (m_nState)
	{
		case eAIS_Idle:
		{
						  if (nNowMS >= m_nStateTime)
						  {
							  int nActType = SelectAction();
							  if (nActType == eATT_Atk)
							  {
								  if (nNowMS >= m_nNextAtkTime)
								  {
									  SetState(eAIS_Atk, GetStateTime(eAIS_Atk), __LINE__);
								  }
								  else
								  {
									  SetState(eAIS_Idle, 300, __LINE__);
								  }
							  }
							  else if (nActType == eATT_Def)
							  {
								  SetState(eAIS_Def, GetStateTime(eAIS_Def), __LINE__);
							  }
						  }
						  break;
		}
		case eAIS_Atk:
		{
						 if (nNowMS >= m_nStateTime)
						 {
							 SetState(eAIS_Idle, GetStateTime(eAIS_Idle), __LINE__);
						 }
						 else
						 {
							 if (m_nLastState != eAIS_Atk)
							 {
								 m_nLastState = eAIS_Atk;
								 m_nNextSearchTime = nNowMS;
								 m_poTarget = NULL;
							 }
							 SearchViewTarget(nNowMS);
							 if (m_poTarget == NULL)
							 {
								 m_nNextSearchTime = nNowMS;
								 SearchNearTarget(nNowMS);
							 }
							 m_poAction->SetTarget(m_poTarget);
						 }
						 break;
		}
		case eAIS_Def:
		{
						 if (nNowMS >= m_nStateTime)
						 {
							 SetState(eAIS_Idle, GetStateTime(eAIS_Idle), __LINE__);
						 }
						 else
						 {
							 if (m_nLastState != eAIS_Def)
							 {
								 m_nLastState = eAIS_Def;
								 m_nNextSearchTime = nNowMS;
								 m_poTarget = NULL;
							 }
							 SearchViewTarget(nNowMS);
							 m_poAction->SetTarget(m_poTarget);
						 }
						 break;
		}
	}
	m_poAction->Update(nNowMS);
}
// ----------------------------------------------------------------------------
// MAINLINE LOGIC
// ----------------------------------------------------------------------------
int main() {
	
	// declarations
	int  action = UNSET;
	char rawPT[BUFFER_SIZE]    = "";
	char cleanPT[BUFFER_SIZE]  = "";
	int  a = A, b = B, inverse = INVERSE, n = ALPHABET_SIZE;
	char nameInputFile[30]     = "input.txt" ;
	char nameOutputFile[30]    = "output.txt";

	// seed the random number generator
	srand((unsigned int)time(NULL));

	// get ready
	action = fGetClnStr(action, rawPT, cleanPT);
	
	// display title page
	DispHeader(nameInputFile, nameOutputFile, a, b, inverse);
	puts("Welcome to Derrida - the command line Affine Cipher!");
	Pause();

	// detail loop
	while(action != QUIT) {
		ClearScreen();

		DispHeader(nameInputFile, nameOutputFile, a, b, inverse);
		
		// select an action
		action = SelectAction(action);
		
		DispHeader(nameInputFile, nameOutputFile, a, b, inverse);

		// execute action
		switch(action) {
		case SET_I_FILE: // change the input file
			action = fGetClnStr(action, rawPT, cleanPT, nameInputFile);
			break;
		case SET_O_FILE: // change the output file
			action = SetOutputFileName(nameOutputFile);
			break;
		case DIR_LIST: // display directory listing
			list_dir();
			break;
		case SET_KEY: // change cipher key
			action = SetCipherKey(a, b, n, inverse);
			break;
		case ENCRYPT: // encrypt the PT codes

			// display the string before encryption
			printf("Before encryption, the string contains:\n");
			puts(rawPT);
			printf("\n");
			printf("Sanatized, the string contains:\n");
			puts(cleanPT);
			printf("\n");
			// if encryption succeeds, inform the user
			if(EncryptString(cleanPT, a, b, n)) {
				FileOutput(nameOutputFile, cleanPT);
				printf("After encryption, the string contains:\n");
				puts(cleanPT);
				printf("\n");
			}

			Pause();
			break;

		case DECRYPT:
			// display the clean cipher code before decryption
			puts("Before decryption, the string contains:");
			puts(cleanPT);
			puts("\n");
			// if decryption succeeds, inform the user
			if(DecryptString(cleanPT, a, b, n)) {
				FileOutput(nameOutputFile, cleanPT);
				puts("After decryption, the string contains:\n");
				puts(cleanPT);
				puts("\n");
			}

			Pause();
			break;	
		}		
	}

	puts("The program will now exit.");
	Pause();

	// exit program
	return 0;
}
Esempio n. 7
0
void ControlDeviceAlter(mUpnpControlPoint *ctrlPoint, int alteration_mask)
{
	mUpnpDevice *selDev;
	mUpnpService *selService;
	mUpnpAction *selAction;
	bool actionSuccess;
	mUpnpArgument *arg;
	char argValue[2048];
	
	printf("Control Device\n");
	
	selDev = SelectDevice(ctrlPoint);
	if (selDev == NULL)
		return;
	selService = SelectService(selDev);
	if (selService == NULL)
		return;
	selAction = SelectAction(selService);
	if (selAction == NULL)
		return;
	
	for (arg = mupnp_action_getarguments(selAction); arg; arg = mupnp_argument_next(arg)) {
		if (mupnp_argument_isindirection(arg) == true) {
			printf("%s : ", mupnp_argument_getname(arg));
			if (scanf("%s", argValue) == 1)
				mupnp_argument_setvalue(arg, argValue);
		}
	}

	/* NOTE: Go through selAction memory management... */
	if (alteration_mask & CMD_LOOP_ACTION_CALLS)
	{
		int loop_count, i;

		printf("\nHow many times action should be sent?");
		
		if ( 1 == scanf("%d", &loop_count) )
		{
			printf("\n");
			for (i=0; i<loop_count; i++)
			{
				actionSuccess = mupnp_action_post(selAction);
				printf("Control Result(%d)\n", (int)actionSuccess);
			}

			mupnp_sleep(3000);

			for (	arg = mupnp_action_getarguments(selAction); 
				arg; 
				arg = mupnp_argument_next(arg)) 
			{
				if (mupnp_argument_isoutdirection(arg) == true)
					printf(" %s = %s\n", 
							mupnp_argument_getname(arg), 
							mupnp_argument_getvalue(arg));
			}

			mupnp_sleep(2000);
		}
	}

	if ((alteration_mask & CMD_NO_ALTERATIONS) == CMD_NO_ALTERATIONS)
	{	
		actionSuccess = mupnp_action_post(selAction);
		
		printf("Control Result(%d)\n", (int)actionSuccess);
		for (arg = mupnp_action_getarguments(selAction); arg; arg = mupnp_argument_next(arg)) {
			if (mupnp_argument_isoutdirection(arg) == true)
				printf(" %s = %s\n", mupnp_argument_getname(arg), mupnp_argument_getvalue(arg));
		}
	}
}