ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Conway's Game of Life in Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 2024
  • In this video, we will implement Conway's Game of Life in Python.
    ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
    📚 Programming Books & Merch 📚
    🐍 The Python Bible Book: www.neuralnine...
    💻 The Algorithm Bible Book: www.neuralnine...
    👕 Programming Merch: www.neuralnine...
    🌐 Social Media & Contact 🌐
    📱 Website: www.neuralnine...
    📷 Instagram: / neuralnine
    🐦 Twitter: / neuralnine
    🤵 LinkedIn: / neuralnine
    📁 GitHub: github.com/Neu...
    🎙 Discord: / discord
    🎵 Outro Music From: www.bensound.com/

ความคิดเห็น • 76

  • @gedtoon6451
    @gedtoon6451 7 หลายเดือนก่อน +1

    When you declare your numpy arrays, you use the default type of nd.float64. This is over the top, as each item in the array will be 0 or 1. It would be better to use nd.int8

  • @vikrantsinghbhadouriya4367
    @vikrantsinghbhadouriya4367 ปีที่แล้ว +10

    Thank you so much dude for making this video!
    Excellent explanation I shall say, I could follow along with each of the steps in almost no time.
    I haven't used numpy so it did took me a while to understood the lines using numpy methods, ( guess shall be learning that soon as well :p)
    Proud seeing my own Conway Game of Life :)
    Thanks!!

  • @pjtren1588
    @pjtren1588 ปีที่แล้ว +4

    Thank you, I felt like I achieved something getting this to run and spotting my mistakes. My first bit of code.

    • @alyme_r
      @alyme_r 10 หลายเดือนก่อน

      your FIRST ? if true ur insane

    • @hezziacGames
      @hezziacGames 5 หลายเดือนก่อน

      DOPE try to make a program to help you program thats what i did i think imma make a vid on it on my other channel good luck!!!
      Happy Coding!

  • @redouanha
    @redouanha 2 ปีที่แล้ว +17

    Can we get the code? i copied the exact same code but somehow it doesn't work for me

    • @nyhrocx
      @nyhrocx 6 หลายเดือนก่อน

      Same here

    • @aramrashid5752
      @aramrashid5752 2 หลายเดือนก่อน

      same here, I think something is missing!

  • @nervous711
    @nervous711 ปีที่แล้ว +2

    4:19 Why not just np.zeros(cells.shape) ?

  • @Mr.somebody.
    @Mr.somebody. ปีที่แล้ว +6

    here's my code it worked for me.
    import time
    import pygame
    import numpy as np
    COLOR_BG = (10, 10, 10,)
    COLOR_GRID = (40, 40, 40)
    COLOR_DIE_NEXT = (170, 170, 170)
    COLOR_ALIVE_NEXT = (255, 255, 255)
    pygame.init()
    pygame.display.set_caption("conway's game of life")
    def update(screen, cells, size, with_progress=False):
    updated_cells = np.zeros((cells.shape[0], cells.shape[1]))
    for row, col in np.ndindex(cells.shape):
    alive = np.sum(cells[row-1:row+2, col-1:col+2]) - cells[row, col]
    color = COLOR_BG if cells[row, col] == 0 else COLOR_ALIVE_NEXT
    if cells[row, col] == 1:
    if alive < 2 or alive > 3:
    if with_progress:
    color = COLOR_DIE_NEXT
    elif 2

    • @michaeltheisen
      @michaeltheisen 6 หลายเดือนก่อน

      Hey Thanks! I copied your code into an editor next to mine to see what I was doing wrong and it turned out to be an indentation in one of my elif statements! Thank you!

  • @mksmvnv
    @mksmvnv 8 หลายเดือนก่อน +1

    Incredible! Thanks for your work!

  • @kaarthikarun9199
    @kaarthikarun9199 2 ปีที่แล้ว +10

    Everybody is a ganster till you see the MONSTER

  • @luigidabro
    @luigidabro ปีที่แล้ว +1

    Recently, I have noticed that an rgb tuple is way faster in rendering than a #

  • @thedeparted_one
    @thedeparted_one 11 หลายเดือนก่อน +2

    Everything works fine, but I am unable to drag the mouse across the board and have cells appear. I can only click each individual cell. Any ideas? Also, is there a github repository of NeuralNine's code?

  • @nasrulislam1968
    @nasrulislam1968 9 หลายเดือนก่อน +1

    How does your alive calculation handle corner cases, for example, the (0,0) cell? Won't it go out of bound?

  • @harmplat7771
    @harmplat7771 7 หลายเดือนก่อน

    Awesome, thanks so much for this clear and consise explanation with all the steps. It works!
    Very helpful for beginners like me.

  • @GHOST_WARRIOR321
    @GHOST_WARRIOR321 2 ปีที่แล้ว +2

    code checked twice and still something it not ok...
    all cells disappear completely, please help

  • @leandronobili9558
    @leandronobili9558 ปีที่แล้ว +1

    hello, i use his method for the main function but when i click with my mouse on the rectangles, that doesn't do anything, i try to copying his code but that doesn't work

  • @CoolMoonCat
    @CoolMoonCat 2 ปีที่แล้ว +4

    It worked, thanks so much! Very clear explanation for a beginner like me.

    • @readynice9972
      @readynice9972 ปีที่แล้ว +1

      stfu you liar it didnt work and still have my code the copy of this full tutorial this motherfucker is a scammer just ruinned 30 min of my life trying to coppy this shit and in the end doesent work wtf

    • @sebastianpolo6271
      @sebastianpolo6271 ปีที่แล้ว

      code is broken, not working for any of us and we copy exactly the code as he instructed. don't Lie

    • @Mr.somebody.
      @Mr.somebody. ปีที่แล้ว +2

      worked for me here is the code.
      import time
      import pygame
      import numpy as np
      COLOR_BG = (10, 10, 10,)
      COLOR_GRID = (40, 40, 40)
      COLOR_DIE_NEXT = (170, 170, 170)
      COLOR_ALIVE_NEXT = (255, 255, 255)
      pygame.init()
      pygame.display.set_caption("conway's game of life")
      def update(screen, cells, size, with_progress=False):
      updated_cells = np.zeros((cells.shape[0], cells.shape[1]))
      for row, col in np.ndindex(cells.shape):
      alive = np.sum(cells[row-1:row+2, col-1:col+2]) - cells[row, col]
      color = COLOR_BG if cells[row, col] == 0 else COLOR_ALIVE_NEXT
      if cells[row, col] == 1:
      if alive < 2 or alive > 3:
      if with_progress:
      color = COLOR_DIE_NEXT
      elif 2

  • @aitsadinassima8469
    @aitsadinassima8469 ปีที่แล้ว

    Thank you so much for this video. You are just amazing.

  • @PunmasterSTP
    @PunmasterSTP 2 ปีที่แล้ว

    Game of life in Python? More like “Cool information that was right on!” Thanks for sharing.

  • @gedtoon6451
    @gedtoon6451 7 หลายเดือนก่อน

    Great video. How would get cells that leave the right side enter on the left side?

  • @apoorvsinha5193
    @apoorvsinha5193 2 ปีที่แล้ว +1

    That's so amazing 😍

  • @lucamanfroi9111
    @lucamanfroi9111 ปีที่แล้ว

    if I were to have an input of starting alive cell coordinates of the "matrix" that is the board, how could I add that to the game, so that it always starts with these exact same starting cells?

  • @elmondo.
    @elmondo. 2 ปีที่แล้ว +1

    Thanks for sharing

  • @justinmuhindomussa7942
    @justinmuhindomussa7942 ปีที่แล้ว

    wonderful game of life
    "assume periodic boundary conditions
    " you did not mention it. can you show how can make it please?

  • @jackjenny8111
    @jackjenny8111 2 ปีที่แล้ว +1

    Mine seems to be leaving grey cells behind. Anyone have any idea why?

  • @SkyFly19853
    @SkyFly19853 2 ปีที่แล้ว +11

    I think using Cython would provide even more performance.

    • @SkyFly19853
      @SkyFly19853 ปีที่แล้ว +1

      @Ralph Reilly
      Have you tried Cython ?

    • @gedtoon6451
      @gedtoon6451 7 หลายเดือนก่อน

      I find the speed of this app fine. Why would you want it to run faster?

    • @SkyFly19853
      @SkyFly19853 7 หลายเดือนก่อน

      @@gedtoon6451
      The faster the better performance for calculations and if statements as well as loops

  • @jm9378
    @jm9378 ปีที่แล้ว +1

    Hi.
    what do you think about the program where we create a kind of "WorldBox"
    For example:
    two groups *, the first in red, the second in blue.
    Each * must "eat", "drink" and strive to reproduce with another * (nice if there were two sexes).
    Each could *eat* the same color or a different color - of course it would depend on which one can "eat". The older ones, for example, could easily defeat the younger ones. Some HP loss during combat. Somewhere on the map scattered *(gray) that would be neutral food. Do you think that such a project can teach you a lot?

    • @Adi-px8eq
      @Adi-px8eq 10 หลายเดือนก่อน

      Hey bro, i just wanted to say that if you have some cool idea, you should try it for yourself instead of being dependent on others. They might not care about you.
      Take care.

    • @moris933
      @moris933 10 หลายเดือนก่อน

      ​@@Adi-px8eq😢

  • @suzerain_k
    @suzerain_k ปีที่แล้ว

    Awesome features in this program. I would like to know if this is parallelizable

    • @DrummingDivingPythonProgrammer
      @DrummingDivingPythonProgrammer 9 หลายเดือนก่อน

      indeed it is. I have no idea if the youtube comment system will allow code, but using numpy arrays and masks will get this done.

  • @Krisler12
    @Krisler12 2 ปีที่แล้ว +5

    Hi!
    Please a video tutorial teaching us how to rename ebooks using python to get their metadata and rename them like author title edition ISBN etc. I think for sure you can use python Calibre package but I didn't find any full tutorial on how to use it. I want to rename many ebooks files in a custom way and also to store metadata information in a database too that's why it should be done using python and not Calibre GUI. Please do such a tutorial. Thank you very much in advance! P.S. I think it is possible to do it with python in other way such using Calibre package but I did just give you a hint.

  • @Mr.somebody.
    @Mr.somebody. ปีที่แล้ว

    how do you change the size of the cells

  • @jacobbiscuitsuuu
    @jacobbiscuitsuuu 8 หลายเดือนก่อน

    Why does Pip install not work for me help

  • @somerandomuserfromootooob
    @somerandomuserfromootooob 2 ปีที่แล้ว +4

    Am i first?????
    Yo man really amazing
    I actually did this in c and it was cool in the terminal. And btw i have a plan to do this in terminal without pygame

    • @kaarthikarun9199
      @kaarthikarun9199 2 ปีที่แล้ว +4

      Everybody is a Gangster till you see the monster

    • @sahilrajwar4997
      @sahilrajwar4997 2 ปีที่แล้ว

      doesn't matter

    • @somerandomuserfromootooob
      @somerandomuserfromootooob 2 ปีที่แล้ว +5

      @@kaarthikarun9199🔥

    • @redchief94
      @redchief94 ปีที่แล้ว

      You can do it. I made an adventure game with ncurses a few years ago, wasn't as bad as I thought it would be.

  • @enriquesuazo7592
    @enriquesuazo7592 7 หลายเดือนก่อน

    vsc tell me that main is not defnined :/

  • @Mr.somebody.
    @Mr.somebody. ปีที่แล้ว

    how to make a reset button?

  • @philtoa334
    @philtoa334 2 ปีที่แล้ว

    Thx.

  • @OrdinarySonicfanMmKay
    @OrdinarySonicfanMmKay ปีที่แล้ว

    only 1 cell appears for me

  • @prem4302
    @prem4302 ปีที่แล้ว

    Where is the code?

  • @riccardoromeo5346
    @riccardoromeo5346 2 ปีที่แล้ว

    i am going insane can someone help please
    code:
    screen = pygame.display.set_mode((800, 600))
    cells = np.zeros ((60,80))
    error:
    TypeError: Cannot interpret '80' as a data type
    i looked everywhere and i alweys found people w the same error becouse thei only used 1 bracket after np.zeros
    and that makes perfect sense becouse it reads the second input as the data type but with two brackets why in the world should
    it read the size as datatype??? please help

    • @lmjlucas
      @lmjlucas 2 ปีที่แล้ว

      try explicitly passing that the types like
      np.zeros(shape=(60,80), dtype=int)

  • @Homelander_69420_
    @Homelander_69420_ 11 หลายเดือนก่อน

    Sneko knows python 😂

  • @TheBuilder
    @TheBuilder 2 ปีที่แล้ว

    hmm I didn't know python was fast enough to handle game of life, but since you're using Numpy the speed up may compensate for the performance of the language

  • @tcgvsocg1458
    @tcgvsocg1458 2 ปีที่แล้ว +1

    wtf i don t understand a simple word you say in this explantion of game!! whats it that?

    • @Synthetic_geth
      @Synthetic_geth 2 ปีที่แล้ว +1

      Just look up "the game of life" you're on the internet

  • @jurijjuras410
    @jurijjuras410 2 ปีที่แล้ว

    nah man i was first

  • @erichsimon5258
    @erichsimon5258 2 ปีที่แล้ว +1

    my grid wont appear and i cant place cells anywhere
    am i missing anything or is anything wrong?
    import time
    import pygame
    import numpy as np
    COLOR_BG = (10, 10, 10)
    COLOR_GRID = (60, 60, 60)
    COLOR_DIE_NEXT = (170, 170, 170)
    COLOR_ALIVE_NEXT = (255, 255, 255)
    def update(screen, cells, size, with_progress = False):
    updated_cells = np.zeros((cells.shape[0], cells.shape[1]))
    for row, col in np.ndindex(cells.shape):
    alive = np.sum (cells[row-1:row+2, col-1:col+2]) - cells[row, col]
    color = COLOR_BG if cells [row, col] == 0 else COLOR_ALIVE_NEXT
    if cells[row, col] == 1:
    if alive < 2 or alive > 3:
    if with_progress:
    color = COLOR_DIE_NEXT
    elif 2

    • @erichsimon5258
      @erichsimon5258 2 ปีที่แล้ว

      i even reviewed the code three times

    • @u4rr837
      @u4rr837 2 ปีที่แล้ว +1

      Maybe your indent got wrong.The 'else:' before 'if alive==3:' should correspond to 'if sell[row,col]==1:' and also check lines behind :D

    • @MaxChip101
      @MaxChip101 ปีที่แล้ว

      i'm having the same issue but i can't see any cells or place any

    • @yousseflaidouni7531
      @yousseflaidouni7531 ปีที่แล้ว

      I think it is just in the last line : < if __name__ == '__main__' > you just gotta add that two _ next to name

    • @adnanmahmud8691
      @adnanmahmud8691 ปีที่แล้ว

      Same problem, the pygame window is not appearing and the code runs for infinity