effectivepython
effectivepython copied to clipboard
item_57.py
I think there should only one game_logic here?
def game_logic(state, neighbors):
# Do some blocking input/output in here:
data = my_socket.recv(100)
def game_logic(state, neighbors):
if state == ALIVE:
if neighbors < 2:
return EMPTY # Die: Too few
elif neighbors > 3:
return EMPTY # Die: Too many
else:
if neighbors == 3:
return ALIVE # Regenerate
return state
and change to
def game_logic(state, neighbors):
# Do some blocking input/output in here:
data = my_socket.recv(100)
if state == ALIVE:
if neighbors < 2:
return EMPTY # Die: Too few
elif neighbors > 3:
return EMPTY # Die: Too many
else:
if neighbors == 3:
return ALIVE # Regenerate
return state
oh It's not wrong, just a confused me.
Thank you for the report! I could see how it's confusing, yeah. I added a comment to the "fake" version with recv that explains its purpose. That will only show up in the example code, not in the book itself.