Exemple #1
0
void Game_Player::Update() {
	bool last_moving = IsMoving() || IsJumping();

	if (IsMovable() && !Game_Map::GetInterpreter().IsRunning()) {
		switch (Input::dir4) {
			case 2:
				Move(Down);
				break;
			case 4:
				Move(Left);
				break;
			case 6:
				Move(Right);
				break;
			case 8:
				Move(Up);
		}
	}

	UpdateScroll();
	Game_Character::Update();

	if (location.aboard)
		GetVehicle()->SyncWithPlayer();

	UpdateNonMoving(last_moving);
}
Exemple #2
0
bool Game_Player::GetOnOffVehicle() {
	if (!IsMovable())
		return false;
	if (InVehicle())
		return GetOffVehicle();
	return GetOnVehicle();
}
void ROBOT_NAVIGATION::ValueIteration(std::vector<std::vector<double> >& V, std::vector<std::vector<int> >& A, double threshold)
{
	std::vector<std::vector<double> > tempV = V;
	for (int i=1; i<=8; i++)
		for (int j=1; j<=8; j++)
		{
			if (ROBOT_NAVIGATION::Map[i][j] == 1 || (i == GoalState.X && j == GoalState.Y)) continue; // Skip the cell of wall & the goal state

			// V(s) = max_{a \in A}(R(s,a) + r*(sum_{s' \in S}(p(s'|s,a)*V(s'))))
			double reward = -1 + Discount * V[i][j]; // For action 0, i.e., action of staying in place
			for (int idx=1; idx<5; idx++) // For other four actions: up, down, left, right
			{
				// calculate the expected reward with the corresponding action
				double expectedSum = 0, p = 0;
				for (int k=1; k<5; k++)
					if (IsMovable(i+ROBOT_NAVIGATION::DeltaAct[k][0], j+ROBOT_NAVIGATION::DeltaAct[k][1]))
						if (idx == k)
						{
							expectedSum += 0.9 * V[i+ROBOT_NAVIGATION::DeltaAct[k][0]][j+ROBOT_NAVIGATION::DeltaAct[k][1]];
							p += 0.9;
						}
						else
						{
							expectedSum += 0.025 * V[i+ROBOT_NAVIGATION::DeltaAct[k][0]][j+ROBOT_NAVIGATION::DeltaAct[k][1]];
							p += 0.025;
						}
				expectedSum += (1-p) * V[i][j];

				double tempReward = -1 + Discount * expectedSum;

				if (tempReward > reward)
				{
					reward = tempReward;
					A[i][j] = idx;
				}
			}
			tempV[i][j] = reward;
		}

	double maxgap = 0;
	for (int i=1; i<=8; i++)
		for (int j=1; j<=8; j++)
			if (ROBOT_NAVIGATION::Map[i][j] == 0)
				if (abs(tempV[i][j] - V[i][j]) > maxgap)
					maxgap = abs(tempV[i][j] - V[i][j]);

	if (maxgap > threshold)
	{
		V = tempV;
		tempV.clear();
		ValueIteration(V, A, threshold);
	}
}
bool ROBOT_NAVIGATION::Step(STATE& state, int action, int& observation, double& reward) const
{
	ROBOT_STATE& robotstate = safe_cast<ROBOT_STATE&>(state);

	if (robotstate.X == GoalState.X && robotstate.Y == GoalState.Y)
	{
		observation = 1 << 8;
		reward = 100;
		return true;
	}

	/*
	 * The actions are up, down, left, right, and stay in place.
	 *
	 * The movement actions move the agent one grid cell in the desired direction with
	 * probability 0.6(or 0.9)or in one of the other directions or current cell with
	 * probability 0.1(or 0.025) each.
	 *
	 * Movements into a wall result in the robot's staying in place.
	 *
	 * Choosing to stay in place always keeps the agent in the current location.
	 */

	int idx; // The resulting moving direction index after performing action
	if (action == 0)
	{
		idx = 0;
	}
	else
	{
		double chance = UTILS::RandomDouble(0, 1.0);
		if (chance < 0.9)
			idx = action;
		else if (chance < 0.925)
			idx = (action + 1) % 5;
		else if (chance < 0.950)
			idx = (action + 2) % 5;
		else if (chance < 0.975)
			idx = (action + 3) % 5;
		else
			idx = (action + 4) % 5;
	}

	int newx = robotstate.X + ROBOT_NAVIGATION::DeltaAct[idx][0];
	int newy = robotstate.Y + ROBOT_NAVIGATION::DeltaAct[idx][1];
	if (IsMovable(newx, newy))
	{
		robotstate.X = newx;
		robotstate.Y = newy;
	} /* Otherwise the robot stays in place, that is, robotstate does not change */

	/*
	 * We assume perfect observation of the grid cells immediately surrounding the agent.
	 * As a result, the robot can observe the wall configurations in surrounding squares,
	 * but not its own actual location.
	 */
	int obs = 0;
	for (int i=0; i<8; i++)
	{
		int obsx = robotstate.X + ROBOT_NAVIGATION::DeltaObs[i][0];
		int obsy = robotstate.Y + ROBOT_NAVIGATION::DeltaObs[i][1];
		if (ROBOT_NAVIGATION::Map[obsx][obsy] == 1)
			obs += 1 << i;
	}
	observation = obs;

	// Reward and terminal state
	reward = -1;

	return false;
}
Exemple #5
0
BOOL CItem::CanDelete()
{
	return IsMovable();
}
Exemple #6
0
BOOL CItem::CanMoveToDialog( cDialog* ptargetdlg )
{
	return IsMovable();
}
Exemple #7
0
void Game_Player::Update() {
	int cur_frame_count = Player::GetFrames();
	// Only update the event once per frame
	if (cur_frame_count == frame_count_at_last_update_parallel) {
		return;
	}
	frame_count_at_last_update_parallel = cur_frame_count;

	bool last_moving = IsMoving() || IsJumping();

	// Workaround: If a blocking move route ends in this frame, Game_Player::CancelMoveRoute decides
	// which events to start. was_blocked is used to avoid triggering events the usual way.
	bool was_blocked = IsBlockedByMoveRoute();
	Game_Character::Update();

	if (!Game_Map::GetInterpreter().IsRunning() && !Game_Map::IsAnyEventStarting()) {
		if (IsMovable()) {
			switch (Input::dir4) {
				case 2:
					Move(Down);
					break;
				case 4:
					Move(Left);
					break;
				case 6:
					Move(Right);
					break;
				case 8:
					Move(Up);
			}
		}

		// ESC-Menu calling
		if (Game_System::GetAllowMenu() && !Game_Message::message_waiting && Input::IsTriggered(Input::CANCEL)) {
			Game_Temp::menu_calling = true;
		}
	}

	Game_Character::UpdateSprite();
	UpdateScroll();

	if (location.aboard)
		GetVehicle()->SyncWithPlayer();

	if (IsMoving() || was_blocked) return;

	if (last_moving && location.boarding) {
		// Boarding completed
		location.aboard = true;
		location.boarding = false;
		SetMoveSpeed(GetVehicle()->GetMoveSpeed());
		SetDirection(GetVehicle()->GetDirection());
		return;
	}

	if (last_moving && location.unboarding) {
		// Unboarding completed
		location.unboarding = false;
		location.vehicle = Game_Vehicle::None;
		CheckTouchEvent();
		return;
	}

	if (InAirship() && !GetVehicle()->IsInUse()) {
		// Airship has landed
		Unboard();
		location.vehicle = Game_Vehicle::None;
		SetDirection(RPG::EventPage::Direction_down);

	}

	if (last_moving && CheckTouchEvent()) return;

	if (!Game_Map::GetInterpreter().IsRunning() && !Game_Map::IsAnyEventStarting()) {
		if (!Game_Message::visible && Input::IsTriggered(Input::DECISION)) {
			if ( GetOnOffVehicle() ) return;
			if ( CheckActionEvent() ) return;
		}
	}

	if (last_moving)
		Game_Map::UpdateEncounterSteps();
}