Heuristic

Hi,

i’m a beginner at mlagents, i played around with the example environments for a while, and took on to make my own flappy bird ai (i thought it’ll be easier considering almost everyone has done this, and i’ll be able to find a lot of resources in case i get stuck)

So i’m stuck here at configuring the actions,

can’t control the agent properly, the button press is not registered everytime,

and since i can’t get the heuristic right, i suppose i won’t be able to train the AI properly.

Heuristic Function

    public override float[] Heuristic()
    {
        var action = new float[1];       
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Pressed");
            action[0] = 1 ;
        }
        else
        {
            action[0] = 0;
        }
        return action;
    }

OnActionReceived Function

    public override void OnActionReceived(float[] vectorAction)
    {
        {
            AddReward(0.01f);
            int action = Mathf.FloorToInt(vectorAction[0]);
            if(action == 0)
            {
            }
            if(action == 1)
            {
                m_AgentRb.velocity = Vector3;
m_AgentRb.AddForce(Vector2.up * tapForce, ForceMode2D.Force);
            }
        }
    }

can’t figure out what’s wrong with this code

Please Help

Hi,

What is triggering the call to RequestDecision on the agent? The Heuristic function will only be called when a decision request is made.

try this Out :

public override void Heuristic(float[] actionsOut)
    {
        actionsOut[0] = Input.GetKeyDown(KeyCode.Space) ? 1 : 0 ;
    }

and make sure your behavior type in behavior parameters is set to default for training Section and Heuristic for debugging Section