Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411476 Posts in 69369 Topics- by 58424 Members - Latest Member: FlyingFreeStudios

April 23, 2024, 05:05:53 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsCellular Automaton / Game of Life (help)
Pages: [1]
Print
Author Topic: Cellular Automaton / Game of Life (help)  (Read 3056 times)
eddieion
Guest
« on: March 02, 2014, 03:35:56 PM »

I've looked around a bit and couldn't find anything relating to my question (but will be pleasantly surprised if there's anything relevant).

I consider myself more of an artist than a coder; but a couple of years ago I became really interested in cellular automata and Conways Game of Life. I've always been interested in making my own (preferably in Game Maker because that's what I have the most experience in, but even then I'm a bit of a layman).

Are there any tutorials or guides that could get me started on a project like this? It needs to be a room of gridded cells in which each cell operates under a simple set of rules based on its surrounding cells.

Sorry if I'm being a bit vague. I just don't know where to even get started trying to do something like this.




http://en.wikipedia.org/wiki/Cellular_automaton

If something like this would be easier to do in Java / Or if alternatively there would be a lot more support or possible tutorials on how to do this with something other than Game Maker then I'd definitely consider that too. Very eager to try out some of my own ideas without trying to painstakingly draw out by hand, frame by frame.
Logged
Glyph
Level 10
*****


Relax! It's all a dream! It HAS to be!


View Profile
« Reply #1 on: March 02, 2014, 05:06:58 PM »

It can be done easily in GM. Use of ds_grids is probably the best way, but you could do it with a 2-d array too.

Anyway, here's a really simple version I whipped up in GM8. Should be pretty self-explanatory.

https://dl.dropboxusercontent.com/u/4841993/game_of_life.gmk
Logged


soryy708
Level 3
***


View Profile WWW
« Reply #2 on: March 02, 2014, 07:41:06 PM »

Go for game maker. More complex things are just overkill.

Funny, because I'm currently working on a Conway's GoL based game too at the moment.
Here's my C++ code for the actual simulation:
Code:
Matrix<bool> backbuffer;
for (int y = state.beginy() - 1; y < state.endy() + 1; ++y)
{
    for (int x = state.beginx() - 1; x < state.endx() + 1; ++x)
    {
        // Calculate neighbours
        int neigh = 0;
        if (state.at(x-1, y-1) == true) ++neigh;
        if (state.at(x  , y-1) == true) ++neigh;
        if (state.at(x+1, y-1) == true) ++neigh;
        if (state.at(x+1, y  ) == true) ++neigh;
        if (state.at(x+1, y+1) == true) ++neigh;
        if (state.at(x  , y+1) == true) ++neigh;
        if (state.at(x-1, y+1) == true) ++neigh;
        if (state.at(x-1, y  ) == true) ++neigh;

        // Any live cell with fewer than two live neighbours dies, as if caused by under-population.
        if (state.at(x, y) == true && neigh < 2)
        {
            backbuffer.set(x, y, false);
        }
        // Any live cell with two or three live neighbours lives on to the next generation.
        if (state.at(x, y) == true && (neigh == 2 || neigh == 3))
        {
            backbuffer.set(x, y, true);
        }
        // Any live cell with more than three live neighbours dies, as if by overcrowding.
        if (state.at(x, y) == true && neigh > 3)
        {
            backbuffer.set(x, y, false);
        }
        // Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
        if (state.at(x, y) == false && neigh == 3)
        {
            backbuffer.set(x, y, true);
        }
    }
}
state = backbuffer;
While it might not be a simple matter of 'copy-paste', I'm sure that you're competent enough to figure out how to translate the general idea of the C++ code to GML.
Feel free to ask me questions!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic