Exemplo n.º 1
0
    public bool SaveState()
    {
        if (hips.localPosition.y < -5.0f)
        {
            MyDoneFunc(true);
            return(false);
        }

        while (current_step >= agent_state_ids.Count)
        {
            agent_state_ids.Add(-1);
        }

        if (agent_state_ids[current_step] == -1)
        {
            agent_state_ids[current_step] = HighLevelGuide.GetNextFreeState(jdController.bodyPartsList.Count);
        }

        int _stateID = agent_state_ids[current_step];

        WalkerAcademy.HumanoidState _cState = HighLevelGuide.savedStates[_stateID];

        current_accumulative_reward        += GetReward();
        _cState.current_accumulative_reward = current_accumulative_reward;
        _cState.current_step = starting_step + current_step;

        for (int i = 0; i < jdController.bodyPartsList.Count; i++)
        {
            _cState.pos[i]  = jdController.bodyPartsList[i].rb.transform.localPosition;
            _cState.rot[i]  = jdController.bodyPartsList[i].rb.transform.localRotation;
            _cState.vel[i]  = jdController.bodyPartsList[i].rb.velocity;
            _cState.aVel[i] = jdController.bodyPartsList[i].rb.angularVelocity;

            _cState.touchingGround[i] = jdController.bodyPartsList[i].groundContact.touchingGround;
            _cState.touchingWall[i]   = jdController.bodyPartsList[i].wallContact.touchingWall;

            _cState.touchingHold[i]   = jdController.bodyPartsList[i].holdContact.touchingHold;
            _cState.touchingHoldId[i] = jdController.bodyPartsList[i].holdContact.hold_id;

            _cState.touchingTarget[i] = jdController.bodyPartsList[i].targetContact.touchingTarget;
        }

        return(true);
    }
Exemplo n.º 2
0
    public bool LoadState(float beta)
    {
        if (HighLevelGuide.sortedTrajectoriesIndices.Count <= 0)
        {
            return(false);
        }

        this.transform.position = parentPos;
        this.transform.rotation = parentRotation;

        // select a trajectory to fork and forking timestep among the best ones
        int nBest = (int)(beta * HighLevelGuide.sortedTrajectoriesIndices.Count);

        updatingTrajectoryIdx = HighLevelGuide.sortedTrajectoriesIndices[Random.Range(0, nBest + 1)];
        WalkerAcademy.WalkerTrajectory forkedTrajectory = HighLevelGuide.savedTrajectories[updatingTrajectoryIdx];
        int forkTimeStep       = Random.Range(0, forkedTrajectory.count_valid_states);
        int forkParentStateIdx = forkedTrajectory.agent_state_ids[forkTimeStep];

        WalkerAcademy.HumanoidState _cState = HighLevelGuide.savedStates[forkParentStateIdx];

        for (int i = 0; i < jdController.bodyPartsList.Count; i++)
        {
            jdController.bodyPartsList[i].rb.transform.localPosition = _cState.pos[i];
            jdController.bodyPartsList[i].rb.transform.localRotation = _cState.rot[i];
            jdController.bodyPartsList[i].rb.velocity        = _cState.vel[i];
            jdController.bodyPartsList[i].rb.angularVelocity = _cState.aVel[i];

            jdController.bodyPartsList[i].groundContact.touchingGround = _cState.touchingGround[i];
            jdController.bodyPartsList[i].wallContact.touchingWall     = _cState.touchingWall[i];

            jdController.bodyPartsList[i].holdContact.touchingHold = _cState.touchingHold[i];
            jdController.bodyPartsList[i].holdContact.hold_id      = _cState.touchingHoldId[i];

            jdController.bodyPartsList[i].targetContact.touchingTarget = _cState.touchingTarget[i];
        }

        starting_step = _cState.current_step;
        return(true);
    }