Beispiel #1
0
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        //comparar la del bot con la del agente

        if (cameraAgent == null)
        {
            cameraAgent = GetComponent <CameraMovement>();
        }

        oX = cameraAgent.GetBotX(); // Se usa para recompensas solo

        oY = cameraAgent.GetBotY();

        if (agentType == AgentType.IMPULSE)     //1 accion
        {
            maxX = Mathf.Clamp(vectorAction[0], -1f, 1f);
            minX = maxX;

            graphicCanvas.AddBotPoint(oX);
            graphicCanvas.AddAgentPointDown(minX);

            if (showStd)
            {
                graphicCanvas.AddAveragePoint(average); //Debug std
                graphicCanvas.AddStdHighPoint(average + stDesv);
                graphicCanvas.AddStdLowPoint(average - stDesv);
            }

            DynamicAverageAndStd(ref moveCount, ref average, ref stDesv, ref varianza, ref averageSquared, oX);
        }
        else if (agentType == AgentType.RANGE)      //2 acciones (X)
        {
            maxX = Mathf.Clamp(vectorAction[0], -1f, 1f);
            minX = Mathf.Clamp(vectorAction[1], -1f, 1f);

            graphicCanvas.AddBotPoint(oX);
            graphicCanvas.AddAgentPointDown(minX);
            graphicCanvas.AddAgentPointUp(maxX);

            if (showStd)
            {
                graphicCanvas.AddAveragePoint(average); //Debug std
                graphicCanvas.AddStdHighPoint(average + stDesv);
                graphicCanvas.AddStdLowPoint(average - stDesv);
            }

            DynamicAverageAndStd(ref moveCount, ref average, ref stDesv, ref varianza, ref averageSquared, oX);
        }
        else if (agentType == AgentType.TWO_AXIS)   //2 acciones (X,Y)
        {
            maxX = Mathf.Clamp(vectorAction[0], -1f, 1f);
            minX = maxX;
            agY  = Mathf.Clamp(vectorAction[1] / YSensitivity, -1f, 1f);

            graphicCanvas.AddAgentPointDown(minX);
            graphicCanvas.AddAgentPointUp(agY);

            graphicCanvas.AddBotPoint(oX);
            graphicCanvas.AddBotPointY(oY);

            graphicCanvas.AddBotAxisPoint(oX, oY);
            graphicCanvas.AddAgentAxisPoint(minX, agY);
        }
        else if (agentType == AgentType.CLICKONLY) //1 accion (click)
        {
            minX = oX;
            maxX = oX;
            agY  = oY;

            //click float
            if (clickDiscrete)
            {
                iClick = Mathf.FloorToInt(vectorAction[0]);
            }
            else
            {
                iClick = Mathf.Clamp(vectorAction[0], -1f, 1f);
            }

            graphicCanvas.AddBotAxisPoint(oX, oY);
            graphicCanvas.AddAgentAxisPoint(minX, agY);

            graphicCanvas.AddAgentPointDown(iClick); // click (no movimiento)

            //Los clicks se procesan por separado

            /*
             * if (cameraAgent.GetBotClick())
             * {
             *  graphicCanvas.AddBotClick();
             * }
             *
             * if ((iClick >= 0f) && (lastClick < 0f))
             * {
             *  graphicCanvas.AddAgentClick();
             * }*/

            graphicCanvas.UpdateLines();
        }
        else if (agentType == AgentType.ANGLE_MAGNITUDE)
        {
            float angle     = (Mathf.Clamp(vectorAction[0], -1f, 1f) + 1f) * Mathf.PI; // en radianes
            float magnitude = (Mathf.Clamp(vectorAction[1], -1f, 1f) + 1f) / 2f;       // de 0 a 1

            minX = magnitude * Mathf.Cos(angle);
            maxX = minX;
            agY  = magnitude * Mathf.Sin(angle);

            graphicCanvas.AddAgentPointDown(minX);
            graphicCanvas.AddAgentPointUp(agY);

            graphicCanvas.AddBotPoint(oX);
            graphicCanvas.AddBotPointY(oY);

            graphicCanvas.AddBotAxisPoint(oX, oY);
            graphicCanvas.AddAgentAxisPoint(minX, agY);


            /*
             * lastAngles.RemoveAt(2);
             * lastAngles.Insert(0, angle);
             * lastMagnitudes.RemoveAt(2);
             * lastMagnitudes.Insert(0, magnitude);*/

            lastAngles.RemoveAt(2);
            lastAngles.Insert(0, Mathf.Clamp(vectorAction[0], -1f, 1f));
            lastMagnitudes.RemoveAt(2);
            lastMagnitudes.Insert(0, Mathf.Clamp(vectorAction[1], -1f, 1f));
        }

        //RewardsStdChIndividualAverage(maxX, oX, average, stDesv, RewFactor, PunFactor, 0.0f);


        //float distance = Vector2.Distance(new Vector2(oX, oY), new Vector2(minX, agY));

        //Debug.Log("oX= " + oX + " , oY= " + oY + " , bX = " + minX + " , bY = " + agY);

        //RewardsTolerableRange(distance, tolerableRange, 2f, PunFactor, RewFactor);

        //AxisRewardAngleMagnitudeTR(tolerableRange, 0.05f, 0.5f, PunFactor, RewFactor, oX, oY, minX, agY);

        //AxisRewardCheatShaped(oX, oY, minX, agY);


        lastX.RemoveAt(59);
        lastX.Insert(0, Mathf.Lerp(minX, maxX, Random.Range(0f, 1f))); // En vez de oX, para que no tenga "chuleta"

        realX.RemoveAt(59);
        realX.Insert(0, oX);

        lastY.RemoveAt(59);
        lastY.Insert(0, agY); // En vez de oX, para que no tenga "chuleta"

        realY.RemoveAt(59);
        realY.Insert(0, oY);
    }