Conway's Game of Life fails with C2 arrays

Get help using Construct 2

Post » Wed Dec 17, 2014 5:29 am

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.
B
5
S
1
Posts: 11
Reputation: 424

Post » Wed Dec 17, 2014 6:13 am

There should be no problem using C2 arrays for this. I don't mind having a look.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Dec 17, 2014 9:26 am

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...:mrgreen:

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!

viewtopic.php?f=148&t=107147&p=792113&hilit=conway#p792113

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.

viewtopic.php?f=163&t=60711&p=522665&hilit=conway#p522665

Of course, if r0j0hound sees this and takes an interest, we might see a C2 version... :D
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Wed Dec 17, 2014 9:29 am

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.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Wed Dec 17, 2014 1:30 pm

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

GameOfLife - tilemap.capx

TiAm wrote: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 HERE and HERE
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Fri Dec 19, 2014 12:18 am

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
You do not have the required permissions to view the files attached to this post.
B
5
S
1
Posts: 11
Reputation: 424

Post » Fri Dec 19, 2014 2:41 am

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
B
5
S
1
Posts: 11
Reputation: 424

Post » Fri Dec 19, 2014 3:05 am

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.
B
5
S
1
Posts: 11
Reputation: 424

Post » Fri Dec 19, 2014 3:18 am

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
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Fri Dec 19, 2014 4:02 am

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.
You do not have the required permissions to view the files attached to this post.
B
5
S
1
Posts: 11
Reputation: 424

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 4 guests