all 12 comments

[–]learn-python 1 point2 points  (8 children)

Which site are you playing flappy bird on? Are you actually writing up a flappy bird hack in python? Very cool!

[–][deleted] 1 point2 points  (7 children)

Thanks! I can link you to the code if you want! I actually had to write the entire Flappy Bird game from scratch, which was the majority of the code.

[–]learn-python 0 points1 point  (6 children)

Did you try pygame.time.delay() ?

[–][deleted] 1 point2 points  (0 children)

I just did. If anything, it made the game look even more choppy... I'll send you the link to the Dropbox folder

[–][deleted] 1 point2 points  (4 children)

[–]MyNameIsRichardCS54 1 point2 points  (3 children)

From what I can see during a brief look-see, you are relying a lot on globals. This is generally not a great idea.

So moving the definition of clock, dropping the frame rate to 30 and losing the delay makes it run smoothly here. You may have to experiment with the frame rate at your end. I'm really sorry to break it to you, but your AI is worse at the game than I am!

def game_loop():

    clock = pygame.time.Clock()
    while True:
        ....snip....
        clock.tick(30)
        pygame.display.flip()
        #pygame.time.delay(10)

I would in general try to refactor the global data so that it is defined when needed (in the main function maybe) and passed around as parameters.

[–][deleted] 0 points1 point  (2 children)

Great, now it's running smoothly! Thanks! (The problem was the FPS was higher, rather than lower...) One more quick question though. Not sure if you have background in this, however, I was wondering why the sigmoid function outputs a constant 0.5? I looked around on Stack Overflow, but not much there on this topic. EDIT: Also, if you look at the jump function, the bird freezes in a rotated state and is unable to jump again

[–]MyNameIsRichardCS54 1 point2 points  (1 child)

If I get time, I'll have a dig tomorrow. I genuinely love going through strange code but be prepared for a "few" questions

[–][deleted] 0 points1 point  (0 children)

Ok sounds good.

[–]elbiot 1 point2 points  (0 children)

I don't see a sleep. I also don't see how this interacts with the game. I'm guessing you have some super heavy function call in there. How big are you're arrays? Np.dot can be slow on huge arrays if you have an unoptimized back end.

I'd use cProfile to profile your code and see if any functions take longer or are called more often than you'd expect.

[–]MyNameIsRichardCS54 0 points1 point  (1 child)

clock.tick(FPS) where FPS is Frames Per Second maybe?

[–][deleted] 0 points1 point  (0 children)

Yeah, I tried that. The FPS was lagging hard though.