Beispiel #1
0
    /**
     * This function returns the time series tuple for the current frame.
     * formate:"ts,mID,mDiff,mType,Lx,Ly,Rx,Ry,Bx,By,Lvel,Rvel,Bvel,Plen,H1input,H2input,composInput,Lscore,Rscore\n"
     *      ts:				timestamp
     *      mID:			match ID
     *      mDiff:			match difficulty
     *      mType:			match type
     *      Lx,Ly:			left paddle x and y position
     *      Rx,Ry:			right paddle x and y position
     *      Bx,By:			ball x and y position
     *      Lvel:			left paddle velocity
     *      Rvel:			right paddle velocity
     *      Bvel:			ball velocity
     *      Plen:			paddle length
     *      H1input:		human 1 input
     *      H2input:		human 2 input (if not applicable, then value is 9999)
     *      composInput:	composite input of both human players (if not applicable, then value is 9999)
     *      Lscore:			left paddle score
     *      Rscore:			right paddle score
     *
     */
    public static string GetTimeSeriesTuple()
    {
        string  t;
        Vector2 garbage = BallUtils.GetBallVelocity();          //TODO: please figure out why removing this breaks everything

        t = GeneralUtils.GetTimeStamp() + ","
            + GeneralUtils.m_dataScript.currMatchNum.ToString() + ","
            + GeneralUtils.GetCurrentMatch().difficulty.ToString() + ","
            + GeneralUtils.GetCurrentConfig().ToString() + ","
            + GeneralUtils.GetHumanPosition().x.ToString() + ","
            + GeneralUtils.GetHumanPosition().y.ToString() + ","
            + GeneralUtils.GetAgentPosition().x.ToString() + ","
            + GeneralUtils.GetAgentPosition().y.ToString() + ","
            + BallUtils.GetBallPosition().x.ToString() + ","
            + BallUtils.GetBallPosition().y.ToString() + ","
            + VelocityUtils.GetVelocity("leftPaddle").ToString() + ","
            + VelocityUtils.GetVelocity("rightPaddle").ToString() + ","
            + VelocityUtils.GetVelocity("ball").ToString() + ","
            + GeneralUtils.GetPaddleSize("Left") + ","
            + GeneralUtils.GetPaddleSize("Right") + ","
            + GeneralUtils.GetHumanInput(1).ToString() + ","
            + GeneralUtils.GetHumanInput(2).ToString() + ","
            + GeneralUtils.GetHumanInput(3).ToString() + ","
            + GeneralUtils.GetPlayerScore("Left").ToString() + ","
            + GeneralUtils.GetPlayerScore("Right").ToString() + "\n";

        return(t);
    }
Beispiel #2
0
    /**
     * This method updates the position of the human player(s) based on the input and
     * match configuration type.
     */
    public void UpdatePosition()
    {
        //get the current configuration type
        byte currConfig = GeneralUtils.GetCurrentConfig();

        //if HvA 1PC: apply changes to left paddle
        if (currConfig == Configuration.HvA_1PC)
        {
            Vector3 p = LeftPaddle.position;

            if (h1Dir > 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h1Dir < 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = LeftPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                LeftPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                LeftPaddle.position = p;
            }
        }
        //if HHvA 1PC: apply changes to left paddle from both inputs
        else if (currConfig == Configuration.HHvA_1PC)
        {
            //store the composite input
            compositeInput = h1Dir;

            Vector3 p = LeftPaddle.position;

            if (h1Dir > 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h1Dir < 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = LeftPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                LeftPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                LeftPaddle.position = p;
            }
        }
        //if HHvA 2PC: apply changes to left paddle from both inputs
        else if (currConfig == Configuration.HHvA_2PC)
        {
            //store the composite input
            if (h1Dir > 0 && h2Dir > 0)
            {
                compositeInput = 1;
            }
            else if (h1Dir < 0 && h2Dir < 0)
            {
                compositeInput = -1;
            }
            else
            {
                compositeInput = 0;
            }

            Vector3 p = LeftPaddle.position;

            if (h1Dir > 0 && h2Dir > 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h1Dir < 0 && h2Dir < 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = LeftPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                LeftPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                LeftPaddle.position = p;
            }
        }
        //if HvH 1PC: apply changes based on the inputs from both human participants
        else if (currConfig == Configuration.HvH_1PC)
        {
            //update left paddle
            Vector3 p = LeftPaddle.position;

            if (h1Dir > 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h1Dir < 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = LeftPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                LeftPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                LeftPaddle.position = p;
            }

            //update right paddle
            p = RightPaddle.position;

            if (h2Dir > 0)
            {
                RightPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h2Dir < 0)
            {
                RightPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = RightPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                RightPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                RightPaddle.position = p;
            }
        }
        //if HvH 2PC: apply changes based on which client this is
        else if (currConfig == Configuration.HvH_2PC)
        {
            //update left paddle
            Vector3 p = LeftPaddle.position;

            if (h1Dir > 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h1Dir < 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = LeftPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                LeftPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                LeftPaddle.position = p;
            }

            //update right paddle
            p = RightPaddle.position;

            if (h2Dir > 0)
            {
                RightPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h2Dir < 0)
            {
                RightPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = RightPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                RightPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                RightPaddle.position = p;
            }
        }
        //if RALLY_1PC or RALLY_2PC
        else if (GeneralUtils.IsRally(currConfig))
        {
            //update left paddle position
            Vector3 p = LeftPaddle.position;

            if (h1Dir > 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h1Dir < 0)
            {
                LeftPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = LeftPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                LeftPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                LeftPaddle.position = p;
            }

            //update left paddle scale
            float   v2              = VelocityUtils.GetVelocity("rightPaddle");
            float   len1            = this.GetLength(v2);
            Vector2 leftPaddleScale = GeneralUtils.GetHumanScale();
            float   wid1            = leftPaddleScale.x * (len1 / leftPaddleScale.y);
            GeneralUtils.SetPaddleSize("leftPaddle", len1, wid1);

            //update right paddle position
            p = RightPaddle.position;

            if (h2Dir > 0)
            {
                RightPaddle.position = new Vector3(p.x, p.y + stepSize * Time.deltaTime, 0);
            }
            else if (h2Dir < 0)
            {
                RightPaddle.position = new Vector3(p.x, p.y - stepSize * Time.deltaTime, 0);
            }

            p = RightPaddle.position;
            if (p.y < yMin)
            {
                p.y = yMin;
                RightPaddle.position = p;
            }
            else if (p.y > yMax)
            {
                p.y = yMax;
                RightPaddle.position = p;
            }

            //update right paddle scale
            float   v1               = VelocityUtils.GetVelocity("leftPaddle");
            float   len2             = this.GetLength(v1);
            Vector2 rightPaddleScale = GeneralUtils.GetAgentScale();
            float   wid2             = rightPaddleScale.x * (len2 / rightPaddleScale.y);
            GeneralUtils.SetPaddleSize("rightPaddle", len2, wid2);
        }
    }