Python Conway's Game of life

preview_player
Показать описание

this video is a speed walkthrough of Conway's Game of life with python using pygame

for Support:

like and Subscribe

thanks For watching
like and Subscribe
Рекомендации по теме
Комментарии
Автор

Thanks for the tutorial! Love the music in the background; it's tech but calming at the same time and doesn't distract or annoy from the actual content.

racheleedwards
Автор

Showing the whole coding process was great. Thanks for this tutorial!

dromn
Автор

Python returned an error: No module named 'grid'

Where do I go from there? How do I solve this?

cdemr
Автор

Wow that's what I was looking for

disdis
Автор

where did you get your soundtrack, I really like listening to it while working

claireatati
Автор

Conway() got an unexpected keyword argument 'surface'

AwS
Автор

Hello, hopefully someone sees this, but mine is static. Does it require a mouse click to get cells moving? I did this on a tablet so I’m not using a mouse.

suomynona
Автор

I don't know if you will see this, but is there a reason for just checking the 4 directly adjacent tiles and not the 4 diagonal tiles as well as those also are counted when getting the total amount of live neighbors?
EDIT: Great Video btw!

timcarlsson
Автор

os comparto el código que encontré en el libro "automate the boring stuff with python"
# Conway's Game of Life
import random, time, copy
WIDTH = 60
HEIGHT = 20

# Create a list of list for the cells:
nextCells = []
for x in range(WIDTH):
column = [] # Create a new column.
for y in range(HEIGHT):
if random.randint(0, 1) == 0:
column.append('#') # Add a living cell.
else:
column.append(' ') # Add a dead cell.
nextCells.append(column) # nextCells is a list of column lists.

while True: # Main program loop.
print('\n\n\n\n\n') # Separate each step with newlines.
currentCells = copy.deepcopy(nextCells)

# Print currentCells on the screen:
for y in range(HEIGHT):
for x in range(WIDTH):
print(currentCells[x][y], end='') # Print the # or space.
print() # Print a newline at the end of the row.

# Calculate the next step's cells based on current step's cells:
for x in range(WIDTH):
for y in range(HEIGHT):
# Get neighboring coordinates:
# `% WIDTH` ensures leftCoord is always between 0 and WIDTH - 1
leftCoord = (x - 1) % WIDTH
rightCoord = (x + 1) % WIDTH
aboveCoord = (y - 1) % HEIGHT
belowCoord = (y + 1) % HEIGHT

# Count number of living neighbors:
numNeighbors = 0
if == '#':
numNeighbors += 1 # Top-left neighbor is alive.
if currentCells[x][aboveCoord] == '#':
numNeighbors += 1 # Top neighbor is alive.
if == '#':
numNeighbors += 1 # Top-right neighbor is alive.
if currentCells[leftCoord][y] == '#':
numNeighbors += 1 # Left neighbor is alive.
if currentCells[rightCoord][y] == '#':
numNeighbors += 1 # Right neighbor is alive.
if == '#':
numNeighbors += 1 # Bottom-left neighbor is alive.
if currentCells[x][belowCoord] == '#':
numNeighbors += 1 # Bottom neighbor is alive.
if == '#':
numNeighbors += 1 # Bottom-right neighbor is alive.

# Set cell based on Conway's Game of Life rules:
if currentCells[x][y] == '#' and (numNeighbors == 2 or
numNeighbors == 3):
# Living cells with 2 or 3 neighbors stay alive:
nextCells[x][y] = '#'
elif currentCells[x][y] == ' ' and numNeighbors == 3:
# Dead cells with 3 neighbors become alive:
nextCells[x][y] = '#'
else:
# Everything else dies or stays dead:
nextCells[x][y] = ' '
time.sleep(1) # Add a 1-second pause to reduce flickering.

juanfernandomoyanoramirez
Автор

Ohk that was crazy...

Could you please increase fount size

drac
Автор

im sorry, this library you used: "grid", can you give me please some info about it? i couldn't find it. Thanks :)

alimartinzynda
Автор

Hi...i have implemented Conway game of life in Python. It works very well if you draw your initial configuration "by hand" using your mouse. Now I want to implement some famous initial configuration (for example a gun or an oscillator) but I don't want to copy it using the mouse...I'm looking for a way to import the grid of a particoular configuration...do you have any idea? Thank you

lucasantagata
Автор

bro m getting a list index out of range when we assign the colors to the cells as in if self.grid_array[i][j] == 1 then we do pygame.draw.rect()

priyanshsoni
Автор

Unoptimized code, very slow to iterate over the 2D array point by point.

brad