effectivepython icon indicating copy to clipboard operation
effectivepython copied to clipboard

item_57.py

Open zhubeilife opened this issue 4 years ago • 2 comments

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

zhubeilife avatar Dec 15 '21 00:12 zhubeilife

oh It's not wrong, just a confused me.

zhubeilife avatar Dec 16 '21 00:12 zhubeilife

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.

bslatkin avatar Jun 01 '24 16:06 bslatkin