I hope this is the right forum to post this....
I created a Python version of the Game of Life, complete with GUI. I utilized an existing game engine and added a GUI on top. You can use the mouse to create the initial board, control the speed and number of generations.
I'm open to adding reading an initial file, etc, if people are interested in using it.
https://user-images.githubusercontent.c ... a87c68.gif
Because PySimpleGUI code tends to be quite compact, the program is maybe 140 lines when you remove the large comment block. Not bad considering the interactivity of it all.
Comments and feedback welcomed.
A Python program with GUI
Re: A Python program with GUI
Good job. I can't say anything else since you're not linking to your program.PySimpleGUI wrote:Comments and feedback welcomed.
-
- Posts: 5
- Joined: December 20th, 2018, 1:58 pm
- Redstoneboi
- Posts: 429
- Joined: May 14th, 2018, 3:57 am
Re: A Python program with GUI
I feel like
could've been
saves a bunch of lines.
it uses the modulo (%) operator, which in x % y results in x wrapping around within range y, exactly what you want.
"continue living" seems like a useless line, doesn't change anything considering you added the "starvation or overcrowding only" part.
also have you considered a list of boolean values to hold the rule? so you could get all the outer totalistic rules.
you could have like a 2*9 array, containing birth rules to survival, so you can explore highlife and life without death and seeds and more!
I'm not really a Python programmer, more of a C++ coder though.
Code: Select all
if (x != self.N and y != self.N):
s += self.old_grid[x][y]
# The remaining branches handle the case where the neighbour is off the end of the grid.
# In this case, we loop back round such that the grid becomes a "toroidal array".
elif (x == self.N and y != self.N):
s += self.old_grid[0][y]
elif (x != self.N and y == self.N):
s += self.old_grid[x][0]
else:
s += self.old_grid[0][0]
Code: Select all
int newX = x % self.N
int newY = y % self.N
# We need to make sure that the neighbor is still on the grid, so we make it wrap around using modulo.
s += self.old_grid[newX][newY]
it uses the modulo (%) operator, which in x % y results in x wrapping around within range y, exactly what you want.
Code: Select all
if (self.old_grid[i][j] == 1 and live < 2):
self.new_grid[i][j] = 0 # Dead from starvation.
elif (self.old_grid[i][j] == 1 and (live == 2 or live == 3)):
self.new_grid[i][j] = 1 # Continue living.
elif (self.old_grid[i][j] == 1 and live > 3):
self.new_grid[i][j] = 0 # Dead from overcrowding.
elif (self.old_grid[i][j] == 0 and live == 3):
self.new_grid[i][j] = 1 # Alive from reproduction.
also have you considered a list of boolean values to hold the rule? so you could get all the outer totalistic rules.
you could have like a 2*9 array, containing birth rules to survival, so you can explore highlife and life without death and seeds and more!
I'm not really a Python programmer, more of a C++ coder though.
c(>^w^<c)~*
This is 「Fluffy」
「Fluffy」is my sutando.
「Fluffy」has the ability to engineer r e p l i c a t o r s.
「Fluffy」likes to watch spaceship guns in Golly.
「Fluffy」knows Natsuki best girl.
This is 「Fluffy」
「Fluffy」is my sutando.
「Fluffy」has the ability to engineer r e p l i c a t o r s.
「Fluffy」likes to watch spaceship guns in Golly.
「Fluffy」knows Natsuki best girl.
-
- Posts: 5
- Joined: December 20th, 2018, 1:58 pm
Re: A Python program with GUI
Thanks for checking out the Life-specific portions. I have barely read through that code to be honest. My contribution to this was strictly the GUI.
I grabbed the code off the net and used as-is, with no modification. I was happy it worked. Credit is at the top.
I appreciate you taking the time to look at the code and write up some concrete suggestions
I grabbed the code off the net and used as-is, with no modification. I was happy it worked. Credit is at the top.
I appreciate you taking the time to look at the code and write up some concrete suggestions