| 75 | |
| 76 | |
| 77 | def count_neighbors(y, x, get_cell): |
| 78 | n_ = get_cell(y - 1, x + 0) # North |
| 79 | ne = get_cell(y - 1, x + 1) # Northeast |
| 80 | e_ = get_cell(y + 0, x + 1) # East |
| 81 | se = get_cell(y + 1, x + 1) # Southeast |
| 82 | s_ = get_cell(y + 1, x + 0) # South |
| 83 | sw = get_cell(y + 1, x - 1) # Southwest |
| 84 | w_ = get_cell(y + 0, x - 1) # West |
| 85 | nw = get_cell(y - 1, x - 1) # Northwest |
| 86 | neighbor_states = [n_, ne, e_, se, s_, sw, w_, nw] |
| 87 | count = 0 |
| 88 | for state in neighbor_states: |
| 89 | if state == ALIVE: |
| 90 | count += 1 |
| 91 | return count |
| 92 | |
| 93 | async def game_logic(state, neighbors): |
| 94 | # Do some input/output in here: |