This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

fishwaffles1337
fishwaffles1337 presents ...

2012/7/19

Game of life

The Game of Life is not your typical computer game. It is a 'cellular automaton', and was invented by Cambridge mathematician John Conway. The Rules

For a space that is 'populated':
Each cell with one or no neighbors dies, as if by loneliness.
Each cell with four or more neighbors dies, as if by overpopulation.
Each cell with two or three neighbors survives.
For a space that is 'empty' or 'unpopulated'
Each cell with three neighbors becomes populated.

5834 views / 24 in the last 7 days

Tags: mouse simulation with-source

open in greenfoot
Your browser does not support the canvas tag.
A new version of this scenario was uploaded on Fri Jul 20 01:30:47 UTC 2012
A new version of this scenario was uploaded on Fri Jul 20 01:32:31 UTC 2012 It now corrisponds with Conway"s rules or life I just need to find a way to get the cells into the game.
A new version of this scenario was uploaded on Mon Jul 30 00:28:02 UTC 2012 Game actually plays now, click to place cells, hold space to run.
DonaldDuckDonaldDuck

2012/7/30

You may want to add a failsafe (if !Greenfoot.isKeyDown("space") { running = false; }) because there is a glitch where if often thinks the spacebar is down when it's not.
@DonaldDuck Where in the code would I put that?
DonaldDuckDonaldDuck

2012/8/14

In the act method or wherever you check for the spacebar being pressed
I'm not sure the rules are being modeled correctly, as several famous configurations like the glider of the F-pentomino do not give the proper results.
danpostdanpost

2012/8/14

I think the problem is due to the code to change each cell is in the act method which will not work properly there. The way it needs to work is that all cells need to be calculated to determine the next state for all the cells before changing any of them. And then, changing all of them at once. In other words, the press of the spacebar should be in the sub-class of world, and each time it is found to be pressed iterate through all the cells to figure out there next states, and then iterate though all the cells, changing to the states figured.
@ Builderboy2005 The rules aren't working properly right now because the world starts full of "empty cells" and placing populated cells on top of them doesn't remove the empty cell class(right now, I'm still trying to figure that). Which means all the cells think they have one more empty cell around them then they actually do.
I just got super busy with school so I probably won't be working on this for a long time, if you like the game there are other completed ones on greenfoot as well many other places online.

See all comments

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.