| 98 | from threading import Thread |
| 99 | |
| 100 | def count_neighbors(y, x, get_cell): |
| 101 | n_ = get_cell(y - 1, x + 0) # North |
| 102 | ne = get_cell(y - 1, x + 1) # Northeast |
| 103 | e_ = get_cell(y + 0, x + 1) # East |
| 104 | se = get_cell(y + 1, x + 1) # Southeast |
| 105 | s_ = get_cell(y + 1, x + 0) # South |
| 106 | sw = get_cell(y + 1, x - 1) # Southwest |
| 107 | w_ = get_cell(y + 0, x - 1) # West |
| 108 | nw = get_cell(y - 1, x - 1) # Northwest |
| 109 | neighbor_states = [n_, ne, e_, se, s_, sw, w_, nw] |
| 110 | count = 0 |
| 111 | for state in neighbor_states: |
| 112 | if state == ALIVE: |
| 113 | count += 1 |
| 114 | return count |
| 115 | |
| 116 | def game_logic(state, neighbors): |
| 117 | # This version of the function is just to illustrate the point |