r/Python • • Oct 06 '19

Playing Flappy Bird with Mixed Integer Programming

1.4k Upvotes

34 comments sorted by

84

u/The_Regent Oct 06 '19

10

u/sleepingcatman Oct 07 '19

This is quite amazing. The way you handle forward simulation of a possible control input as constraints reminds me of the multiple direct shooting method in optimal control.

4

u/The_Regent Oct 07 '19

Yes, ths is very much a trajectory optimization. I think this style where you lay out the path and control trajectory is called a direct collocation method.

29

u/ishmandoo Oct 06 '19

Wow, that second blog post is much better you should all read that one.

34

u/The_Regent Oct 06 '19

Nah. i don't think so. I think you should click only the first one and forget the second was ever there.

31

u/The_Regent Oct 06 '19

Also Ben smells weird. Whoever he is.

128

u/ishmandoo Oct 06 '19

You guys sound smart, especially your friend Ben.

1

u/x-w-j Feb 12 '20

Ben holds a PhD in Physics from Brown if that qualifies.

3

u/appsplaah Oct 07 '19

Awesome! I am a newbie to python, but wont be for much long.

Do you mind telling me how did you do it? Might help newbies like me.

The way i think is you took the flappy bird ios/android app and then "by some way" you integrated your Python algorithm(correct me if i am wrong).

Just curious about it :p Thanks for the Inspiration!

3

u/The_Regent Oct 07 '19

Nope. We used a python flappy bird clone written in pygame (that we did not write) as a starting point. So the whole thing is in python. The hack you're suggesting would be significantly harder.

The original: https://github.com/sourabhv/FlapPyBird

Our modified fork: https://github.com/philzook58/FlapPyBird-MPC

4

u/appsplaah Oct 07 '19

Sounds even Gr8 :) Thanks

14

u/davidwolf995 Oct 07 '19

It's guys like you that motivate me to keep learn python. This is amazing.

2

u/MaesterCrow Oct 07 '19

So basically your controlling the birds future?

8

u/The_Regent Oct 07 '19

Yes. I wouldn't advise crossing us. We are very powerful.

3

u/ishmandoo Oct 07 '19

Basically! We predict into the future in order to correctly plan the next step.

28

u/Unlock17A Oct 06 '19

There's no way this is og flappy bird. Og one was so much harder

38

u/o11c Oct 07 '19

You mean the helicopter game?

9

u/[deleted] Oct 07 '19

Nostalgia.

4

u/liquidpele Oct 07 '19

Right... because it fucking cheated!

3

u/VeryCleverMoose Oct 07 '19

Looks like the jump height is reduced

5

u/fenom500 Oct 07 '19

It really wasn’t though, at least not at lower numbers like this. I was easily getting to 200 so with a computer playing, it looks even easier

11

u/Ph0X Oct 07 '19

I'm not saying the original was impossible but it was still harder than this. The bounces were basically the same height as the distance between pipes or more, so to pass through, you needed to press space lower than the bottom pipe. Here, the bird is doing lots of tiny bounces that are 1/3 the height of the entrance. This is nowhere near the real difficulty...

https://youtu.be/fQoJZuBwrkU

This implementation is the one posted on this sub a month ago. It's not the real game, but a remake in python, and it definitely does not have the same parameters when it comes to jump height and pipe distance.

4

u/ishmandoo Oct 07 '19

You're definitely right that this isn't the original implementation and I think you're right about the jump height too. I'll make the jump height bigger tonight and see how it runs. Feel free to clone the the repo and play with the parameters.

3

u/[deleted] Oct 07 '19

Ben is really smart. You should be greatful.

1

u/gapje666 Oct 07 '19

I guess you had a lot of strings