I'm working on a simple version of Conway's Game of Life. When I input something such as 0001, the output should be 1010. The program handles the 1's and 0's as bools.
In the code snippet below, I'm printing the 'copy' variable, which should only change once per generation. Instead, it's changing every time the for loop loops. Why is 'copy' changing? Shouldn't 'state' be the only thing that's changing?
def adj(state,i):
a = b = False
if i == 0: #checking on left wall
a = state[-1]
b = state[i+1]
elif i == len(state)-1: #checking on right wall
a = state[i-1]
b = state[0]
else: #checking in the middle
a = state[i-1]
b = state[i+1]
return [a,b].count(True)
def evolve(state):
copy = state #changes are made to state based on the copy
for i in range(len(copy)):
print(copy)
if adj(copy,i) == 1:
state[i] = True
else:
state[i] = False
return state