Help for training FlappyBird
I have read the official documents but I still don't know how to set the parameters in order to train the flappy bird game. I followed the official tutorials to make a flappy bird like game. The bird has a rigidbody and use addForce to move up when it meets columns or want to avoid falling in ground. So how can I decide the state parameters and action parameters? Or is there any document can explain more details about the ML-agents source code. Thx first.
Concerning the state space, you have to tell the agent what the environment looks like (partially or completely). Maybe the bird is told its distance to the next two obstacles and the height of the gaps. Also, the agent could cast some rays to sense obstacles.
The action space sounds to me quite simple. One action is flapping and the other action is doing nothing at all.
edit: Part of the input space should be the velocity of the bird as well.
Hi @JKbasara,
I would second what @MarcoMeter recommends. Be sure also to give the bird a reward for each time it makes it through a pipe, (or for each step of the engine it is still alive).
If you haven't already, I would recommend checking out our documentation section: https://github.com/Unity-Technologies/ml-agents/tree/master/docs
I defined two states (the distance between bird and ground ,the distance between bird and columns/gaps) and one action is addForce(flap the bird).
Now I use raycast to check the distance, but I don't know how to code the logic function.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
this is my setting.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ this is code I have write,but it can't work.
public override List<float> CollectState()
{
List<float> state = new List<float>();
state.Add (hDistance); // distance between bird and column
state.Add (vDistance); // distance between bird and ground
return state;
}
public override void AgentStep(float[] act)
{
if (brain.brainParameters.actionSpaceType == StateType.continuous) {
float action_AddForce = act [0];
if (action_AddForce > 1.0f) {
action_AddForce = 1.0f;
}
if(hDistance < 1.5f || vDistance < 1.5f){
BirdFlap ();
}
if (done == false)
{
reward = 0.1f;
}
}
if (isBirdDead == true) {
GameController.instance.ReloadScene ();
done = true;
reward = -1.0f;
}
}
public override void AgentReset()
{
gameObject.transform.position = new Vector2(0.0f,Random.Range (1.0f, 5.0f));
}
public override void AgentOnDone()
{
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ I built the game scene followed the official tutorial ,so the bird just add a up force ,the background and columns scroll. So anyone can tell me how to define the states , action and so on.
Thx ^_^
Hi @JKbasara
for your environment, I suggest to use the discrete action space. This would require to work with two actions: to flap or not to flap.
public override void AgentStep(float[] act)
{
int action = (int)act[0];
if(action == 0)
{
BirdFlap ();
}
else
{
// Don't flap
}
}
Concerning your state space, I would measure the distances right inside the CollectState() function.
As state inputs, I would use a normalised Y position + instead of distance, I would use relative X and Y to the gate between the pipes - so three state inputs: y, relative x and y between bird and pipes. This is assuming the position of the hole between the pipes changes.
Hi @JKbasara , thanks for reaching out to us. Hopefully you were able to resolve your issue. We are closing this due to inactivity, but if you need additional assistance, feel free to reopen the issue.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.