Ejemplo n.º 1
0
        public override void ChildUpdate()
        {
            List <GameStateSummary> gss = this.statsLogger.lifeTimeState.games;

            gss = gss.LastN(10);
            if (this.statsLogger.gameState != null)
            {
                gss.Add(new GameStateSummary(this.statsLogger.gameState));
            }
            gss.Reverse();

            int total     = 0;
            int gameCount = 0;

            for (int i = 0; i < 10; i++)
            {
                GameStateSummary data = null;
                if (i < gss.Count)
                {
                    data       = gss[i];
                    total     += data.score;
                    gameCount += 1;
                }

                gameSummaries[i].UpdateGUI(data);
            }

            if (gameCount > 0)
            {
                averageScore.text = Mathf.RoundToInt(total / (float)gameCount).ToString("000000");
            }
        }
    public void InitializeFromGame(GameObject selfObj, GameObject childObj)
    {
        this.observedAction = new ObservedAction();
        this.observedAction.InitializeFromGame();

        this.gameStateSummary = new GameStateSummary(this.goal);
        this.gameStateSummary.InitializeFromGame(selfObj, childObj);
    }
    public void InitializeFromSaved(string s)
    {
        string[] splits = s.Split('|');

        this.gameStateSummary = new GameStateSummary(this.goal);
        this.gameStateSummary.InitializeFromSaved(splits [0]);

        this.observedAction = new ObservedAction();
        this.observedAction.InitializeFromSaved(splits [1]);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Overwrites the parent rotation input; basically this is called every frame to
    /// get the inputs to the first person controller
    /// </summary>
    protected override void GetRotationInput(bool usingJoystick)
    {
        GameStateSummary gss = new GameStateSummary(this.goal);

        gss.InitializeFromGame(GameObject.Find("AIController(Clone)"), GameObject.Find("AIFirstPersonCharacter"));
        ObservedAction action = this.network.GetPredictedAction(gss);

        // uncomment to print current action as CSV
        //Debug.Log (action);
        this.yInput = action.yRotInput;
        this.xInput = 0f;         //action.xRotInput; //* 5.0f;
        //this.xInput = 0f;
    }
Ejemplo n.º 5
0
        public void UpdateGUI(GameStateSummary gss)
        {
            if (gss == null)
            {
                this.gameObject.SetActive(false);
                return;
            }

            gameObject.SetActive(true);
            startLevel.text         = gss.startLevel.ToString("00");
            score.text              = gss.score.ToString("00");
            lines.text              = gss.linesCleared.ToString("000");
            startLevelBlockA.sprite = BlockTextureGenerator.Instance.getLevelSprite(gss.startLevel, BlockTextureGenerator.Border.ORIGINAL, BlockTextureGenerator.BlockType.PRIMARY);
            startLevelBlockB.sprite = BlockTextureGenerator.Instance.getLevelSprite(gss.startLevel, BlockTextureGenerator.Border.ORIGINAL, BlockTextureGenerator.BlockType.SECONDARY);
        }
    public ObservedAction GetPredictedAction(GameStateSummary gss)
    {
        double[]       input  = { gss.XZAngleToObj, gss.YZAngletoObj, gss.distToObj };
        double[]       output = this.network.Compute(input);
        ObservedAction action = new ObservedAction();

        action.yRotInput        = (float)output [0];
        action.xRotInput        = (float)output [1];
        action.horizontalPan    = (float)output [2];
        action.forwardPan       = (float)output [3];
        action.fireButtonDown   = (float)output [4];
        action.sprintButtonDown = (float)output [5];
        action.jumpButtonDown   = (float)output [6];
        return(action);
    }
    protected override void GetInput(out float speed)
    {
        // Read input
        //manually setting
        //float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
        GameStateSummary gss = new GameStateSummary(this.goalState);

        gss.InitializeFromGame(this.gameObject, GameObject.Find("AIFirstPersonCharacter"));
        ObservedAction action = this.network.GetPredictedAction(gss);

        Debug.Log(string.Format("{0}|{1}", gss.PrettyPrint(), action.PrettyPrint()));
        this.isJumping = action.jumpButtonDown > 0.5;         //TODO: tune these magic thresholds
        m_IsWalking    = !(action.sprintButtonDown > 0.5);
        float horizontal = action.horizontalPan;
        //float vertical = CrossPlatformInputManager.GetAxis("Vertical");
        float vertical = action.forwardPan;

        this.isFiring = (action.fireButtonDown > 0.15f);

        bool waswalking = this.m_IsWalking;



        // set the desired speed to be walking or running
        speed   = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
        m_Input = new Vector2(horizontal, vertical);

        // normalize input if it exceeds 1 in combined length:
        if (m_Input.sqrMagnitude > 1)
        {
            m_Input.Normalize();
        }

        // handle speed change to give an fov kick
        // only if the player is going to a run, is running and the fovkick is to be used
        if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
        {
            StopAllCoroutines();
            StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
        }
    }