Coding “Conway’s Game of Life” Cellular Automaton in C++/ SFML

Coding “Conway’s Game of Life” Cellular Automaton in C++/ SFML


87 thoughts on “Coding “Conway’s Game of Life” Cellular Automaton in C++/ SFML”

  1. I actually made a sun in game of life once, couldn't find anything like it on the internet, so i was pretty happy with myself

  2. For people (including Hopson) that are interested in this concept, check out Dr. Brian lorgon111 who programs in Minecraft. He's a cool guy as well 🙂 https://www.youtube.com/watch?v=GMEES9O6UCQ

  3. How is the board being updated? Are you storing all the new cells until you've gone through all of them and then display the change, or are you just doing one at the time?

  4. Game of life is actually my first SFML project ever

    I didn't know about vertex arrays so I was writing to an sf::Image, then converting to a texture.

    But I wanted to zoom and stuff and I didn't know about sf::View either

    so I was rendering to a RenderTexture.

    Really really bad code, but it worked and it's cool

  5. Where did you learn OpenGL? I find no good Tutorial to learn it. (Im a Java-programmer, so i have to work with lwjgl instead of SFML)

  6. A few years ago I made a Game of Life where the cells would inherit rules, but with a chance of "mutation" like evolution. I couldn't get very interesting results. The cells would either get a bad rule and die off or get a good rule and cover the board.

  7. Awesome video, I have a few questions: What other stable structures arise? Are there things with more complicated movement patterns than gliders? And last, how different do things end up if you start with a slightly different set of filled squares?

  8. Jyothiraditya Nellakra

    How would using a boolean for storing the state of a cell have made your code any less readable?

    You could simply have written this in the class where the cells are defined:
    #define alive true
    #define dead false

    That would have eliminated the need for an enumerator while making the class.

  9. I also created a Game of Life Simulator half a year ago in Java 😀 it had a map creator and random world generator depending on an entered seed and you could also change the rules your own 🙂 It was a lot of fun to create just because you could see much progress in a small amount of time 😀
    Nice to see you also building such a simulator now! 🙂

  10. Since each cell can only be either dead or alive, wouldn't it technically be better to store all the cells in a large array and use bitwise manipulation to read out the states as represented by individual bits in the array? I mean, obviously it's more convoluted, but seeing as the minimum storage size for most machines is 8 bits, using a separate Boolean or enum for each cell would effectively mean increasing the memory allocation size by 8 compared to a single array…

  11. You could have seriously increased the fps by having three matrices instead of two, so that one matrix would represent neighbours making it far more efficient to calculate the number of neighbours that each and every cell has.

  12. you could probably save a few keystrokes by doing git add . or git add -A instead of –all (i'm quite new to coding in general so feel free to tell me if/why i'm wrong)

  13. I once did an interesting challenge in CUDA. Code Conway's game of life in 3D (adjusting the numbers of course). If CUDA is a tech that interests you, I can only suggest you to do it 🙂

  14. I made this in unity, but when I run it with 90*160 the fps averages out at 4. I update all cells before rendering each frame. I used quads as well, and tried to optimize as much as I could code wise. The camera takes most of the performance (rendering quads with the simplest possible shader). How can yours be so blazingly fast with such a huge amount of pixels? Did you pre-render it, or is your c++ code just that much more powerful?

    The camera rendering is 50% of the performance, but just the update alone is also already 40%. So even if rendering would be completely free, I would still only get 8 fps. How can that be possible?

    Great video btw, love your vids!

  15. switch statement for the rules in cpp:

    switch (neighbours)
    {
    case 0:field[x][y] = 0; break;
    case 1:field[x][y] = 0; break;
    case 2:break;
    case 3:field[x][y] = 1; break;
    case 4:field[x][y] = 0; break;
    case 5:field[x][y] = 0; break;
    case 6:field[x][y] = 0; break;
    case 7:field[x][y] = 0; break;
    case 8:field[x][y] = 0; break;
    default: break;
    }

  16. When I tried coding it, the whole Automaton almost instantly turns into a bunch of selfsustaining formations, that either don't move at all, or have a blinking pixel somewhere.
    Sadly there are no gliders, or even spinners, or anything that moves…

Leave a Reply

Your email address will not be published. Required fields are marked *