0 Favourites

Conway's Game of Life fails with C2 arrays

  • Hello,

    I tried implementing a basic version of Conway's Game Of Life using a small 6x6 C2 array. Something about the way C2 loops the array in a foreach seems to cause the grid to improperly propagate the standard tests. I can get the statics to work as expected but the oscillators do not, a typical blinker for example transforms to a block in 2 ticks.

    Has anyone out there created CGOL in C2 and willing to take a look at what i have? As best I can tell it has something to do with C2 traversing the y dimensions of an array before the x dimensions. For width N it runs x1,y1 then x1,y2. Its the only thing that seems odd about how its running and like i said the statics work so somehow the transformations have to be looking at the neighbors incorrectly.

    thanks.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • There should be no problem using C2 arrays for this. I don't mind having a look.

  • I'd LOVE to see something like this. CGOL is such a beautiful...algorithm? cellular automaton? I truely have trouble looking away from running conway sim...it's hypnotizing...

    I've thought before that it would be interesting to try and build a literal game around it, where you started with an initial state and some sort of goal. Never really got into the specifics.

    ...and, someone beat me to it. Damn my procrastination!

    Also, here's a vanilla implementation in CC; would be worth firing up to see how the logic is setup, would probably be pretty similar in C2.

    Of course, if r0j0hound sees this and takes an interest, we might see a C2 version...

  • One more: a cool low rez, canvas based implementation by Minor. Has a capx linked too:

    https://dl.dropboxusercontent.com/u/164 ... index.html

    Doesn't look too complicated. Shouldn't be hard to get a tilemap implement going.

  • Here's my version as posted above using a tilemap instead of Rojohound's canvas plugin.

    [attachment=0:1rcfxsw9][/attachment:1rcfxsw9]

    I've thought before that it would be interesting to try and build a literal game around it, where you started with an initial state and some sort of goal. Never really got into the specifics.

    ...and, someone beat me to it. Damn my procrastination!

    TiAm I made some prototypes in Construct Classic using CGOL for a platform game. Videos can be found https://www.youtube.com/watch?v=X6Ns0qrxbYc&list=UUSSn-fw8tBJAIJq8RDFax0A

    HERE

    and https://www.youtube.com/watch?v=wRFBSeiLwz0&list=UUSSn-fw8tBJAIJq8RDFax0A

    HERE

  • Wow, thanks everyone for responding; I am very thankful to have so much to review/absorb.

    If anyone cares to point out my error, Im uploading my sample. Its pretty basic, Im not trying to do anything visual yet. You'll want to run it in debug mode so you get the inspector. In there you'll see an object 'boolStates' that has a small grid. You'll see that a set of them are arranged in a line to force a common oscillator pattern. In a single iteration that pattern should reflect across the alternate axis if the algorithm is processing correctly. Since C2 isnt raw code I am trying to work out the order of operation through the event system by having the game's ticking controlled by a toggle on that red square; so you click to start, click again to pause.

    Since the loaded grid has an oscillator the expected behavior is that each tick it reflects and alternates ( my use of reflect and alternate may not be accurate ). Instead what I see is that the form transforms into a static box which then maintains the static state. This would imply that somewhere in the loop the state on a 'neighbor' is inaccurate or I am looking at the neighbors wrong. I assume C2 has to be processing correctly so I feel like 70/30 I have something wonky in my order of operation or 'neighbor' detection.

    Any insight would be great. CGOL is a great way to learn.

    Thanks

  • Actually I think I have an idea what Im doing wrong. I am trying to process the grid with a foreach. I have a feeling if I make a better loop the weirdness will disappear and i'll have my immortal oscillator as planned mwahahahaha.

    Minor, I tried to load your project but it told me I needed version .91 and seems i can only get .90?

    TiAm, thanks for the source material that canvas plugin is a good tool to have.

    Thanks

  • Yup, looks like my issue was that i conflated the lookup for neighbors with the application of the rules. I did what 'Rhound' did-ish and stored my sum in an extra dimension of my grid so now i can iterate over those values independently. Stupid monkey.

  • r191 is a beta. You can get it here:

    https://www.scirra.com/construct2/releases/r192

    Minor's approach is to loop over the array twice. The first time it saves the neighbors for each cell, and the second time it apply's the cgol rules. With yours it appears you're just finding the neighbors and applying the rules as you go, which will cause issues as you go since you're modifying the array as you go.

    I tried a slightly different approach which also works. I basically used two arrays and each step I alternate which one I read cells from and which ones I write to.

    https://dl.dropboxusercontent.com/u/542 ... /cgol.capx

    That is one of about six different capx's I've been playing with.

    There are many other ca's that look interesting to implement as well. Here's just a few:

    http://www.mirekw.com/ca/ca_rules.html

    And the latest capx of a different set of cool looking ca's

    https://dl.dropboxusercontent.com/u/542 ... yclic.capx

  • Thanks R0j0hound,

    Here's what I have now, it seems to work. Im going to try reverting the for loops back to foreach and see if i just had an error somehow. I added the extra dimension and split the operation in two parts as you did but doing both loops with foreach on the array and using the built in cursor index objects kept giving it strange values. I took foreach out and created nested named loops to get indexes from and now it oscillates as expected.

    I'm very excited to start my actual project now that this 'life engine' works.

  • One last post to tie this all together. This is an example using what I did, with R0j0hound's Canvas plugin plus the 'abstract' idea of actually using CGOL for something other than rendering cellular automata. I dont know exactly what I will do with this yet, but sharing for the next person who gets curious, hopefully better with math than I.

    http://a178489.sb2.codeanywhere.net/cgolengine/

    In this example, if you click the red box you will start the generations. You'll start to see some stuff happening in a black-ish box and then see another flickering box in the center that started out as green.

    Whats happening is the generations are ticking away updating the preloaded oscillator pattern. That pattern in that location in the grid creates other distinct phenomenon around it at each change. So I draw the updates into 'plots' in R0j0hound's canvas and read the color data to see if i should update the animation frame or not. When the oscillator is in the 'A' position it will fire a green box, and when in the 'B' a yellow box in another location so that I could also compare both together. This is a simple way that the game engine causes procedural updates through related systems.

    Thanks again to everyone who helped me putter through this lab.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)