Пример #1
0
    public void MoveRacket(PongAgent agent, float action)
    {
        if (agent.brain.brainParameters.vectorActionSpaceType == MLAgents.SpaceType.continuous)
        {
            action = action + 1;    //input action will be -1,0,1 for continuous action space
        }
        float actionInt = Mathf.Clamp(action, ActionDown, ActionUp);

        Debug.Assert(actionInt >= ActionDown && actionInt < ActionUp + 1);

        if (agent == leftAgent)
        {
            //move the rackets
            currentGameState.leftY += racketSpeed * (actionInt - 1);
            currentGameState.leftY  = Mathf.Clamp(currentGameState.leftY, -arenaSize.y / 2 + racketWidth / 2, arenaSize.y / 2 - racketWidth / 2);
        }
        else if (agent == rightAgent)
        {
            currentGameState.rightY += racketSpeed * (actionInt - 1);
            currentGameState.rightY  = Mathf.Clamp(currentGameState.rightY, -arenaSize.y / 2 + racketWidth / 2, arenaSize.y / 2 - racketWidth / 2);
        }
        else
        {
            Debug.LogError("Wrong agent");
        }
    }
Пример #2
0
 public float[] CurrentState(PongAgent actor)
 {
     float[] result = null;
     if (actor == leftAgent)
     {
         result = new float[] {
             currentGameState.leftY,
             currentGameState.rightY,
             currentGameState.ballPosition.x,
             currentGameState.ballPosition.y,
             currentGameState.ballVelocity.x,
             currentGameState.ballVelocity.y
         };
     }
     else if (actor == rightAgent)
     {
         result = new float[] {
             currentGameState.rightY,
             currentGameState.leftY,
             -currentGameState.ballPosition.x,
             currentGameState.ballPosition.y,
             -currentGameState.ballVelocity.x,
             currentGameState.ballVelocity.y
         };
     }
     else
     {
         Debug.LogError("Wrong agent");
     }
     return(result);
 }