Python Flappy Bird AI Tutorial (with NEAT) - Finishing the Graphics

  Рет қаралды 74,750

Tech With Tim

Tech With Tim

Күн бұрын

Пікірлер: 112
@extremetitan2847
@extremetitan2847 5 жыл бұрын
I accidentally switched pipe.png with bird.png, it was amazing XD
@arnewaumans5024
@arnewaumans5024 4 жыл бұрын
when I saw this comment, I knew I had to try it
@ibuucoksiregar9024
@ibuucoksiregar9024 4 жыл бұрын
Flappy pipe
@selimustel577
@selimustel577 5 жыл бұрын
You are doing very well with this tutorial series, also i would like to see the full projects livestream 6 7 or more hours :) i think your channel is going to get bigger exponentially if you keep doing. Thanks man!
@Marc_B.4
@Marc_B.4 5 жыл бұрын
For those who have "TypeError: integer argument expected, got float" error in collide, just do: top_offset = (self.x - bird.x, int(self.top - round(bird.y))) bottom_offset = (self.x - bird.x, int(self.bottom - round(bird.y)))
@namigaliyev5894
@namigaliyev5894 5 жыл бұрын
int(round(bird.y))
@ibuucoksiregar9024
@ibuucoksiregar9024 4 жыл бұрын
its weird that round() leaves float behind
@chuhokyinhkbuas2337
@chuhokyinhkbuas2337 4 жыл бұрын
one quick tip. ALWAYS BLIT THE BACKGROUND FIRST IN YOUR redraw window function or else every objects will be covered by your background.
@Danielagostinho21
@Danielagostinho21 5 жыл бұрын
Every video i'm getting more anxious for the next video
@tristansun3274
@tristansun3274 5 жыл бұрын
gotta love this series
@gabriellima6248
@gabriellima6248 2 жыл бұрын
My window is too big to see on the computer screen and because of that i can't see the base image, it's not that its' not there if i check all my windows open by doing a 3 finger swipe up on a mac i can see it, but i can't see it when it have it "maximized" because the 800 pixel height seems to be too big to fit on my screen vertically, does anyone have suggestions?
@Andrei-zh5jv
@Andrei-zh5jv 5 жыл бұрын
Thanks for the upload frequency
@Soljarag5
@Soljarag5 5 жыл бұрын
Thanks!!!!!!! So far I have gotten this to work.... on to the next video tomorrow.
@infinitespace1982
@infinitespace1982 2 жыл бұрын
7:49 At this point, I try to run my code, it works fine but when the bird is halfway through passing the first pipe, the game freezes and then crashes for some reason. Can anyone please help me?
@shuvadass7525
@shuvadass7525 4 жыл бұрын
Can I use NEAT in Reinforcement Learning? Especially to a simple monte Carlo prediction/ control problem where an agent can be the genome and its policy can be gene. Do I have to build an equivalent Neural Network with MC logic first in order to apply NEAT or does it not matter, any simple NN would do without the MC logic?
@tombil-certon
@tombil-certon 5 жыл бұрын
Amazing video Tim :D
@pranjal1100
@pranjal1100 4 жыл бұрын
My first pipe renders fine, rest of the pipe sort stack up one another, how do i adjust the distance bw two pices? Note: Distance b/w first and second pipe is fine and can adjusted by the "pipes.append(Pipes(distance))"
@kevinliu5060
@kevinliu5060 4 жыл бұрын
I know its kinda late, but I had the same problem. I did a little editing in the code and somehow got it to work. Remove = [] add_pipe = False for pipe in pipes: pipe.move() if pipe.collide(bird): pass if pipe.x + pipe.Pipe_Top.get_width() < 0: Remove.append(pipe) if not pipe.passed and pipe.x < bird.x: pipe.passed = True add_pipe = True if add_pipe: score += 1 pipes.append(Pipe(Display_Width)) for r in Remove: pipes.remove(r) draw_window(win, bird, pipes, base) Hope it helps!
@sashamuller9743
@sashamuller9743 4 жыл бұрын
@@kevinliu5060 for future people with the same problem. you must add pipe.passed = True as shown in the code above by Kevin Liu and Tim's code
@tigernav3350
@tigernav3350 4 жыл бұрын
@@kevinliu5060 holy shit thanks
@techtutorials8812
@techtutorials8812 4 жыл бұрын
"That's what I've figured out is kinda like the best position". Isn't it better to figure out what, say two-fifths of the way from the left is, and use that, rather than hard-coding in the values? Same with the base, better to use the height of the window minus the height of the image.
@aiden4053
@aiden4053 5 жыл бұрын
Great video! Can't wait for the next one, keep it up!
@vp9041
@vp9041 5 жыл бұрын
Waiting for the next one
@samwillis1856
@samwillis1856 4 жыл бұрын
Hi, been watching this series for the last day and going through it. Was just wondering if you had any videos on how to implement it so it's just playable as a game and nothing to do with ai. just wanted to create this so me and my friends can play it! thanks!
@user-hd6xc1xn9d
@user-hd6xc1xn9d 4 жыл бұрын
Make the jump function activated by a click or a spacebar press
@sashamuller9743
@sashamuller9743 4 жыл бұрын
he has a great video on space invaders, that show how to implement key inputs from the user and get the player to move around. also check the last video in this series where he implements the keystrokes to be done by the A.I, in order to reference how the jump() and move() methods are used to get the bird to jump
@jonathanfisher6644
@jonathanfisher6644 3 жыл бұрын
im sure this is super janky but put this in the for event in pygame.get(): loop if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: bird.jump()
@cjclines3611
@cjclines3611 5 жыл бұрын
Hi Tim, i have an issue with this bit; def main(): bird = Bird(230, 350) base = Base(730) pipes = [Pipe(700)] win = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT)) clock = pygame.time.Clock() you are at the part where you are starting to code the base moving, but ive ran the code and i have pipes already showing and the base is glued to the top of the window? im very confused, any help would be greatly recieved.
@cjclines3611
@cjclines3611 5 жыл бұрын
Edit: dont worry all sorted stupid me messed up with the initial self.y = y bit
@23kaz51
@23kaz51 4 жыл бұрын
Hey, if we do not make "add_pipe" false again, then there will be mess with pipes. I wrote exactly what you wrote, and mess appeared. After I made "add_pipe" false again after "pipes.append(Pipe(600))", then everything worked well. The main question is WHY?
@23kaz51
@23kaz51 4 жыл бұрын
Stupid question. I didn't notice that you created "add_pipe" in the while-loop
@JoaoGuilherme-ez8xm
@JoaoGuilherme-ez8xm 3 жыл бұрын
bro thank you so much for this, I was having this same issue!!
@jasarosker7726
@jasarosker7726 Жыл бұрын
Does any1 have same problem as me? When I run the code, opens normal etc... but it's like zoomed in. I only see top half of the game.
@jamminwithyou2
@jamminwithyou2 Жыл бұрын
I have the same issue and the pipe that's on the floor is stuck to the top of the screen.
@harryleib4303
@harryleib4303 4 жыл бұрын
i cant adjust the image sizes to my scren... could someone help me please? the imgaes seems too big and i cant see the base img
@iamo
@iamo 4 жыл бұрын
use the following code to fit image to size of your window: BG_IMG = pygame.transform.scale(pygame.image.load(os.path.join("imgs", "bg.png")), (WIN_WIDTH, WIN_HEIGHT))
@electronics_8722
@electronics_8722 4 жыл бұрын
Very nice tutorials! everything works perfect!
@chekystar
@chekystar 4 жыл бұрын
best tutorial ever: even better with 0.5 play speed you sound sooo stoned :P i hope that you are not using tenserflow for ai cause it doesnt work on my "calculator" :)
@novicephiladelphia.d4788
@novicephiladelphia.d4788 5 жыл бұрын
Great ! Hope there will have some videos about optimizing the code :p
@anshulraj1237
@anshulraj1237 4 жыл бұрын
Was following the tutorial and when I did ctrl b to run I got this AttributeError: 'Pipe' object has no attribute 'set_height' what should I do?
@AgentRex42
@AgentRex42 5 жыл бұрын
When I try to run it doesn't work. I have "TypeError: draw() missing 1 required positional argument: 'win' "...
@NotxarbProd
@NotxarbProd 5 жыл бұрын
ME TOO I AM ABOUT TO KILL PC
@anawilliams1332
@anawilliams1332 3 жыл бұрын
same
@harshdeeptelang127
@harshdeeptelang127 3 жыл бұрын
@@NotxarbProd lmaao
@penneshells5448
@penneshells5448 4 жыл бұрын
I have coded up to 8.06 and the first pipe appears bit not a second pipe. No error message or anything. Any reason this might happen would be great, thanks!
@penneshells5448
@penneshells5448 4 жыл бұрын
Never mind, no clue what I did, but it seems okay now.
@aniketbhattacharjee1123
@aniketbhattacharjee1123 3 жыл бұрын
hey bro, I dont know why but the my pipe seems to render behind the bird and stays there only. any help?
@lees852
@lees852 2 жыл бұрын
I am having trouble with get_mask() it keep saying arguument 1 must be pygame.surface not list.
@jhonalkas5560
@jhonalkas5560 4 жыл бұрын
HELP! Everything is fine when I run the script but the second I get to my first pipe it crashes, does anyone know a fix?
@ibuucoksiregar9024
@ibuucoksiregar9024 4 жыл бұрын
make sure you typed: for r in rem: pipes.remove(r) i typed pipes.append instead of pipes.remove
@smurfgreen5741
@smurfgreen5741 4 жыл бұрын
I'm a bit late... but if it isnt what the comment above says, then it is most likely you did not make score = 0 underneath "clock = pygame.time.Clock" should be around line 177ish Hope this helps : )
@leoliu6143
@leoliu6143 4 жыл бұрын
Jhon Alkas I think the problem is that you have to write the remove and add pipe statement outside the for loop, hope helped:)
@degstenk
@degstenk 4 жыл бұрын
@@ibuucoksiregar9024 helped
@8pczzz
@8pczzz 2 жыл бұрын
@@leoliu6143 kuddos to you sir, was going crazy over here trying to figure it out
@huytruongle519
@huytruongle519 4 жыл бұрын
TypeError: draw() takes 1 positional argument but 2 were given help pls
@toastybread7085
@toastybread7085 4 жыл бұрын
make sure everywhere draw() is written you have the same items inside
@jagadishb14
@jagadishb14 4 жыл бұрын
Hey Tim I was also coding this, I thought why not ai plays Mario forever can you make one this game please. Many people like Mario too
@vyddikkk
@vyddikkk 5 жыл бұрын
help pleas self.set_height() AttributeError: 'Pipe' object has no attribute 'set_height'
@huytruongle519
@huytruongle519 4 жыл бұрын
@Coding Call i checked all of them and cannot find a spelling mistake
@huytruongle519
@huytruongle519 4 жыл бұрын
oh i accidentally indented them all nvm
@ScriptLineStudios
@ScriptLineStudios 4 жыл бұрын
For some reason my bird freezes when it passes the first pipe
@smurfgreen5741
@smurfgreen5741 4 жыл бұрын
I'm a bit late... but for anyone else that may be struggling in the future and to stop you from having a breakdown like i did: score = 0 underneath "clock = pygame.time.Clock" should be around line 177ish timestamp is 5.56 Hope this helps : )
@leoliu6143
@leoliu6143 4 жыл бұрын
I think the problem is that you have to write the remove and add pipe statement outside the for loop, hope helped:)
@tthelix
@tthelix 4 жыл бұрын
@@smurfgreen5741 You the real MVP
@hrishikeshghongane5027
@hrishikeshghongane5027 4 жыл бұрын
My pipes are not visible, not able to figure the issue.
@sagittario8796
@sagittario8796 2 жыл бұрын
bird object has no attribute 'mask' how do i fix this ?
@joshuawheeler3255
@joshuawheeler3255 4 жыл бұрын
I have everything working correctly, but the game is running extremely slowly. It is almost less than a frame a second. It has been doing so since the very beginning when I put just the bird on the screen and had it flap its wings. I have a decently new gaming laptop, so hardware should not be the problem. My cpu/gpu usage is tiny, and I have plenty of ram. Do you have any idea what is wrong? I restarted computed and disabled windows defender, but neither option helped. These videos are great BTW, thanks.
@TechWithTim
@TechWithTim 4 жыл бұрын
Make sure you don’t have too low of a delay or that your clock speed isn’t too low.
@joshuawheeler3255
@joshuawheeler3255 4 жыл бұрын
@@TechWithTim I'm sorry I'm not sure what you mean. What delay? And are you talking about the stock clock speed of my CPU or something else?
@matthewbrown4782
@matthewbrown4782 4 жыл бұрын
Joshua Wheeler If you right click on the app that opens in your dock when you run Pygame, click options, open in finder, right click python, click get info, and under general check “open in low resolution”
@betterer
@betterer 5 жыл бұрын
Great vid
@sashamuller9743
@sashamuller9743 4 жыл бұрын
i'm not really sure what pipe.passed is, could anyone help?
@jbg0801
@jbg0801 4 жыл бұрын
anyone know how to fix the error: bad operand type for unary +: 'str' when referring to the line text = STAT_FONT.render("Score: ", + str(score), 1, (255, 255, 255))
@AirFling
@AirFling 4 жыл бұрын
This may be a bit late. but remove the comma after "Score: "
@adityasoma1294
@adityasoma1294 4 жыл бұрын
what code should we input if we want to control the bird manually. pls advise.
@kristianlynes5908
@kristianlynes5908 4 жыл бұрын
i also want to know this, commenting for if someone comes with an answer
@ZenithYap
@ZenithYap 3 жыл бұрын
what does self.passed do?
@aryanbhatia6992
@aryanbhatia6992 5 жыл бұрын
Amazing Video.
@ayhanardal
@ayhanardal Жыл бұрын
I get the error " 'Pipe' object is not iterable" when i run for loop with pipes
@jamminwithyou2
@jamminwithyou2 Жыл бұрын
Had the same problem. Make sure pipes = [Pipe(700)] in the coding.
@exelbernardi6493
@exelbernardi6493 5 жыл бұрын
Amazing video,
@ballistics8818
@ballistics8818 4 жыл бұрын
"base has no attribute move" did i miss something?!?
@anshulraj1237
@anshulraj1237 4 жыл бұрын
What did you do to solve this similar problem with pipe
@MA-hk3qg
@MA-hk3qg 3 жыл бұрын
def draw_window(win, bird, pipes, base, *score*) ... *score* += 1 ... draw_window(win, bird, pipes, base, *score*) I keep getting the error message: line 221, (the score += line), in main draw_window(win, bird, pipes, base, score) UnboundLocalError: local variable 'score' referenced before assignment
@MA-hk3qg
@MA-hk3qg 3 жыл бұрын
Help!
@ibuddywolfie7882
@ibuddywolfie7882 5 жыл бұрын
Someone PLEASE help me, I have been working on fixing this error for an hour and a half minimum, and I even rewritten my code following this video 4 times. I get the following error: AttributeError: Bird instance has no attribute 'img' when I try and do "if pipe.collide(bird):" Please someone help me! Edit: I just want to put this out here, I modified no code at all when rewriting to see if it was my modifications or not, but when I rewrote this code exactly letter by letter from the video, I still get the same error! If any more details is needed for someone to help me, please let me know! I need help :c Edit 2: This error also causes lots of other errors in my code, the one on the very top is on line 82, where the get_mask is. The error is on the return line. Another error is on line 114 for the collide, the code for that line is "bird_mask = bird.get_mask()". I don't know if these are what caused AttributeError but yeah, can someone please help me?
@charlestilden1268
@charlestilden1268 5 жыл бұрын
Have you checked the capitalization of the variables? I noticed that was an issue when doing this tutorial.
@indrektalving4425
@indrektalving4425 5 жыл бұрын
Make sure you have "self.img = self.IMGS[0]" in your Bird __init__. By following everything line by line I had it wrong for some reason
@NurglesToes
@NurglesToes 4 жыл бұрын
@@indrektalving4425 thanks for this. also had quite a few problems with going line by line lol.
@playnolife
@playnolife 4 жыл бұрын
keep getting: in main base = Base(730) TypeError: Base() takes no arguments can someone help :C
@playnolife
@playnolife 4 жыл бұрын
nvm i used _index_ instead of _init_
@adamkerkemeyer
@adamkerkemeyer 4 жыл бұрын
@@playnolife interesting coincidence we had the same spelling mistake
@kevinliu5060
@kevinliu5060 4 жыл бұрын
Wow thanks Lol I had "int" instead of "init" and it took for forever to realize until I saw this comment
@likithas1286
@likithas1286 4 жыл бұрын
****** Running generation 0 ****** C:/Users/TANMAY/PycharmProjects/helloworld/NEAT-Flappy-Bird-master/flappy_bird.py:252: DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python. new_rect = rotated_image.get_rect(center=image.get_rect(topleft=topleft).center) Please help me with this error!
@NotxarbProd
@NotxarbProd 5 жыл бұрын
PLEASE PLEASE PLEASE HELP ME THE HEIGHT OF THE WINDOW IS TOO BIG FOR MY SCREEN SO I CANT SEE THE GROUND OR BASE
@sainco3036
@sainco3036 5 жыл бұрын
thanks.
@AgentRex42
@AgentRex42 5 жыл бұрын
Cool !
@totoma3297
@totoma3297 4 жыл бұрын
my score isn't going up anyone have any idea why
@yabbieo8466
@yabbieo8466 3 жыл бұрын
I know its late.. for some reason my score is behind the background.. Haven't figured out how to fix it yet..
@aunkitchaki9943
@aunkitchaki9943 3 жыл бұрын
@@yabbieo8466 hey man I am facing this same issue, any idea how to solve this?
@pravachanpatra4012
@pravachanpatra4012 2 жыл бұрын
9:00
@ark5458
@ark5458 4 жыл бұрын
my own reference dont mind me 4:13
@shridumanish3506
@shridumanish3506 4 жыл бұрын
My base goes upwards lol
@ibuddywolfie7882
@ibuddywolfie7882 5 жыл бұрын
Hi so I wrote a help comment last night and its still not fixed, and instead of editing that one and making it another 10000000000 characters longer, I figured I would make a new comment. My get_mask errors, and the code is: def get_mask(self): return pygame.mask.from_surface(self.img) The error is: AttributeError: Bird instance has no attribute 'img' Can someone help? tysm
@NotxarbProd
@NotxarbProd 5 жыл бұрын
IBuddyWolfie try changing img to IMG
@alialmeerahmed6994
@alialmeerahmed6994 4 жыл бұрын
7.30
@VerifyBot
@VerifyBot 5 жыл бұрын
Welp anyone else having this problem?? imgur.com/a/GrTz37D
@Cliper1011
@Cliper1011 3 жыл бұрын
Can i directly remove the pipe from pipes instead of append it to remove then removing it. pipes.remove(pipe) like this
@josima
@josima 4 жыл бұрын
my bird freezes when it gets to the first pipe :(
@smurfgreen5741
@smurfgreen5741 4 жыл бұрын
I'm a bit late... but for anyone else that may be struggling in the future and to stop you from having a breakdown like i did: score = 0 underneath "clock = pygame.time.Clock" should be around line 177ish timestamp is 5.56 Hope this helps : )
@BerryTwoC
@BerryTwoC 4 жыл бұрын
It could also be because of indentation, I had that problem as well when my add_pipe condition was within the for loop for pipes.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 13 МЛН
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 8 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 63 МЛН
Making a Game With C++ and SDL2
8:14
PolyMars
Рет қаралды 1,7 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 98 МЛН
A.I. Learns to play Flappy Bird
7:46
Code Bullet
Рет қаралды 14 МЛН
C++ Developer Learns Python
9:26
PolyMars
Рет қаралды 2,8 МЛН
Build a Python Website in 15 Minutes With Streamlit
18:37
Tech With Tim
Рет қаралды 81 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 735 М.
Python Flappy Bird AI Tutorial (with NEAT) - Moving Birds
18:27
Tech With Tim
Рет қаралды 172 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 13 МЛН