| 95 | |
| 96 | |
| 97 | def count_neighbors(y, x, get_cell): |
| 98 | n_ = get_cell(y - 1, x + 0) # North |
| 99 | ne = get_cell(y - 1, x + 1) # Northeast |
| 100 | e_ = get_cell(y + 0, x + 1) # East |
| 101 | se = get_cell(y + 1, x + 1) # Southeast |
| 102 | s_ = get_cell(y + 1, x + 0) # South |
| 103 | sw = get_cell(y + 1, x - 1) # Southwest |
| 104 | w_ = get_cell(y + 0, x - 1) # West |
| 105 | nw = get_cell(y - 1, x - 1) # Northwest |
| 106 | neighbor_states = [n_, ne, e_, se, s_, sw, w_, nw] |
| 107 | count = 0 |
| 108 | for state in neighbor_states: |
| 109 | if state == ALIVE: |
| 110 | count += 1 |
| 111 | return count |
| 112 | |
| 113 | def game_logic(state, neighbors): |
| 114 | # Do some blocking input/output in here: |