Exemplo n.º 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);
    }
Exemplo n.º 2
0
 /**
  * Instance constructor.
  */
 public ObjPositionSample(float _x_, float _y_)
 {
     t = VelocityUtils.GetLongMillisecond();
     x = (int)_x_;
     y = (int)_y_;
 }
Exemplo n.º 3
0
 /**
  * Instance constructor.
  */
 public ObjPositionSample(int _x_, int _y_)
 {
     t = VelocityUtils.GetLongMillisecond();
     x = _x_;
     y = _y_;
 }
Exemplo n.º 4
0
    void Update()
    {
        //only log data if role is server
        if (GeneralUtils.GetProcessRole() == GeneralUtils.ROLE_SERVER)
        {
            /** TIME SERIES LOGGER AUTOMATON **/
            //CURRENT STATE: SESSION NOT YET STARTED
            if (timeSeriesAuto.CurrState == TimeSeriesLogAutomaton.SESSION_NOT_STARTED)
            {
                //if a session begins
                if (GeneralUtils.SessionInProgress())
                {
                    //set the filenames to be produced
                    string mainFileName = "";
                    if (GeneralUtils.GetNumHumanPlayers() == 2)
                    {
                        mainFileName = GeneralUtils.GetHuman1Name() + "__" + GeneralUtils.GetHuman2Name();
                    }
                    else
                    {
                        mainFileName = GeneralUtils.GetHuman1Name();
                    }
                    mainFileName            += "__" + GeneralUtils.GetSelectedSessionName();
                    eventOutputFileName      = eventOutputFileName.Replace("NONAME", mainFileName);
                    timeSeriesOutputFileName = timeSeriesOutputFileName.Replace("NONAME", mainFileName);
                    metadataOutputFileName   = metadataOutputFileName.Replace("NONAME", mainFileName);

                    //enact transition to the next state
                    timeSeriesAuto.Transition(TimeSeriesLogAutomaton.MATCH_NOT_STARTED);
                }
            }
            //CURRENT STATE: MATCH NOT YET STARTED
            else if (timeSeriesAuto.CurrState == TimeSeriesLogAutomaton.MATCH_NOT_STARTED)
            {
                //if a match begins
                if (GeneralUtils.MatchInProgress())
                {
                    //clear the string builder object
                    sb = new StringBuilder();

                    //append the file header
                    sb.Append("ts,mNum,mDiff,mCfg,Lx,Ly,Rx,Ry,Bx,By,Lvel,Rvel,Bvel,Llen,RLen,H1input,H2input,composInput,Lscore,Rscore\n");

                    //enact transition to the next state
                    timeSeriesAuto.Transition(TimeSeriesLogAutomaton.ACCUMULATING_SAMPLES);
                }

                //if the session is completed
                if (!GeneralUtils.SessionInProgress())
                {
                    //enact transition to the next state
                    timeSeriesAuto.Transition(TimeSeriesLogAutomaton.SESSION_COMPLETED);
                }
            }
            //CURRENT STATE: ACCUMULATING SAMPLES
            else if (timeSeriesAuto.CurrState == TimeSeriesLogAutomaton.ACCUMULATING_SAMPLES)
            {
                //if the session is completed
                if (!GeneralUtils.SessionInProgress())
                {
                    //log the accumulated samples
                    StreamWriter sw = new StreamWriter(timeSeriesOutputFilePath + timeSeriesOutputFileName, true);
                    sw.Write(sb.ToString());
                    sw.Close();

                    //enact transition to the next state
                    timeSeriesAuto.Transition(TimeSeriesLogAutomaton.SESSION_COMPLETED);
                }
                //otherwise
                else
                {
                    //if the match ends
                    if (!GeneralUtils.MatchInProgress())
                    {
                        //log the accumulated samples
                        StreamWriter sw = new StreamWriter(timeSeriesOutputFilePath + timeSeriesOutputFileName, true);
                        sw.Write(sb.ToString());
                        sw.Close();

                        //increment the match count
                        currMatchNum += 1;

                        //enact transition to the next state
                        timeSeriesAuto.Transition(TimeSeriesLogAutomaton.MATCH_NOT_STARTED);
                    }
                    //otherwise
                    else
                    {
                        //if five seconds have passed
                        if (DateTime.Now.Subtract(lastWriteTime).TotalMilliseconds > 5000)
                        {
                            //log the accumulated samples
                            StreamWriter sw = new StreamWriter(timeSeriesOutputFilePath + timeSeriesOutputFileName, true);
                            sw.Write(sb.ToString());
                            sw.Close();

                            //capture the current time
                            lastWriteTime = DateTime.Now;

                            //clear the string builder
                            sb = new StringBuilder();
                        }
                        //otherwise, log the sample
                        else
                        {
                            //store samples for moving objects in order to track velocity
                            VelocityUtils.UpdateObjPositionSamples();

                            //append the sample to the string builder
                            sb.Append(GeneralUtils.GetTimeSeriesTuple());
                        }
                    }
                }
            }
            //CURRENT STATE: SESSION COMPLETED
            else if (timeSeriesAuto.CurrState == TimeSeriesLogAutomaton.SESSION_COMPLETED)
            {
            }


            /** METADATA LOGGER AUTOMATON **/
            //CURRENT STATE: SESSION INFO HAS NOT YET BEEN ENTERED
            if (metadataAuto.CurrState == MetadataLogAutomaton.NOT_ENTERED_SESSION_INFO)
            {
                //if the session information begins to be entered
                if (GeneralUtils.GettingSessionInfoFromUser())
                {
                    //enact transition to the next state
                    metadataAuto.Transition(MetadataLogAutomaton.GETTING_SESSION_INFO);
                }
            }
            //CURRENT STATE: GETTING SESSION INFO
            else if (metadataAuto.CurrState == MetadataLogAutomaton.GETTING_SESSION_INFO)
            {
                Match currMatch = GeneralUtils.GetCurrentMatch();

                //if session info has been successfully entered and the session begins
                if (GeneralUtils.SessionInProgress() && currMatch != null)
                {
                    //store the entered information in the metadata object
                    metadata.date              = DateTime.Now.Date.ToString();
                    metadata.p1ID              = GeneralUtils.GetParticipantID(1);
                    metadata.p2ID              = GeneralUtils.GetParticipantID(2);
                    metadata.sessionID         = GeneralUtils.GetSessionID();
                    metadata.startOfSession    = GeneralUtils.GetTimeStamp();
                    metadata.hrsGamesPerWeekP1 = GeneralUtils.GetHrsGamesPerWeek(1);
                    metadata.hrsGamesPerWeekP2 = GeneralUtils.GetHrsGamesPerWeek(2);
                    metadata.collaborative     = GeneralUtils.IsCollaboration(currMatch.configuration.shorthandConfig);
                    metadata.therapistPlaying  = currMatch.configuration.therapistPlaying;
                    metadata.interactionType   = currMatch.configuration.shorthandConfig;

                    //enact transition to the next state
                    metadataAuto.Transition(MetadataLogAutomaton.SESSION_INFO_ENTERED);
                }
            }
            //CURRENT STATE: FINISHED GETTING SESSION INFO
            else if (metadataAuto.CurrState == MetadataLogAutomaton.SESSION_INFO_ENTERED)
            {
                //if the session ends
                if (!GeneralUtils.SessionInProgress())
                {
                    //log metadata to a file
                    metadata.endOfSession = GeneralUtils.GetTimeStamp();
                    metadata.Save(metadataOutputFilePath + metadataOutputFileName);

                    //enact transition to the next state
                    metadataAuto.Transition(MetadataLogAutomaton.SESSION_COMPLETE);
                }
            }
            //CURRENT STATE: SESSION COMPLETE
            else if (metadataAuto.CurrState == MetadataLogAutomaton.SESSION_COMPLETE)
            {
            }
        }
    }
Exemplo n.º 5
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);
        }
    }