Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / conway's game of life

Author
Message
qwedsa
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location:
Posted: 3rd Jun 2013 23:51
for the life of me i cannot get Game of Life to run properly. I've coded it on darkbasic, I've been through the code many times. any help would be appreciated

it manually sets a gosper-glider-gun, there must be a problem with teh rules for the game because it just dissipates rather than produce gliders, and when i set it with random cells, there are no oscillators, it just sets into a permanent pattern

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 4th Jun 2013 01:28
First off, you could try setting all the zero state cells as well as the one state ones.

At the moment they are defaulting to an un-initialized value which may not be zero.

Secondly, and probably more importantly, you might want to post this in the Dark Basic Section
Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 4th Jun 2013 01:36
When you count the neighbor cells it seems like you only count the 4 corner cells because of the "u <> x and v <> y" part. I just took a quick look so I may be wrong.
qwedsa
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location:
Posted: 4th Jun 2013 02:33
thanks ranietz!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jun 2013 04:37
Quote: "until done = 1"

I don't see a global declaration for done and I don't see anywhere that it is either initialised or changed. So this loop never ends.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Jun 2013 09:19
There's a fundamental error here:

You are destroying the information as you scan. You need two "boards." The second board is initially blank. Scan the first board and if a cell is "live" make it live in the second board.

When you've done this, display the second board, clear the first board and then do it the other way around.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jun 2013 11:20 Edited at: 5th Jun 2013 11:22
For fun I coded up a simple Life program using Delphi XE3. You can run it straight out of the zip file because it doesn't need images. The source file is in the zip.

To save you wading through the whole file, here are main bits:

Declarations:


One nice Pascal feature is that arrays can be declared with a sub-range. Declaring from -1 mean that the board has a kind of empty frame of one cell around it. This means you can calculate the surround count without any conditionals.

We need two boards. Here are all the private declarations:



The key procedures are Breed and GetCount:



That works because a "live" cell has a value 1, and an empty cell has zero. Counting the actual cell and subtracting its value make things easier and faster, because there are no conditionals.

The board is updated on a timer. The actual operational code can be computed thousands of times per second, so we just fire it at 40 milliseconds or 1000 milliseconds.

The display code is totally separate from the calculation code, so having debugged it thoroughly in Delphi it would be easy to move this to AGK. The calculation stuff will work fine on any platform.

When programming games I find it massively faster to get the workhorse code working in a powerful visual designer, and then worry about the graphics interface afterwards. If the algorithmic stuff is mixed with the graphics it's much harder to debug.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL

Attachments

Login to view attachments
qwedsa
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location:
Posted: 6th Jun 2013 17:04
it works fine with ranietz correction
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 7th Jun 2013 00:54
I doubt it!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL

Login to post a reply

Server time is: 2024-11-24 15:48:19
Your offset time is: 2024-11-24 15:48:19