-
Notifications
You must be signed in to change notification settings - Fork 0
/
ww_next.py
56 lines (45 loc) · 1.67 KB
/
ww_next.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import copy
def adjcheck(x, y, array, rowsno, colsno):
total = 0
if y - 1 >= 0: # y-1 won't be out of bounds
if x - 1 >= 0: # x-1 won't be out of bounds
if array[y - 1][x - 1] == 1: # top left
total += 1
if array[y - 1][x] == 1: # top middle
total += 1
if x + 1 <= (colsno - 1): # x+1 won't be out of bounds
if array[y - 1][x + 1] == 1: # top right
total += 1
if x - 1 >= 0: # x-1 won't be out of bounds
if array[y][x - 1] == 1: # middle left
total += 1
if x + 1 <= (colsno - 1): # x+1 won't be out of bounds
if array[y][x + 1] == 1: # middle right
total += 1
if y + 1 <= (rowsno - 1): # y+1 won't be out of bounds
if x - 1 >= 0: # x-1 won't be out of bounds
if array[y + 1][x - 1] == 1: # bottom left
total += 1
if array[y + 1][x] == 1: # bottom middle
total += 1
if x + 1 <= (colsno - 1): # x+1 won't be out of bounds
if array[y + 1][x + 1] == 1: # bottom right
total += 1
if 0 < total < 3:
return True
else:
return False
def main(array):
rowsno = (len(array)) # y coord
colsno = (len(array[0])) # x coord
changed = copy.deepcopy(array)
for y in range(rowsno):
for x in range(colsno):
if (array[y][x] == 1) or (array[y][x] == 2):
changed[y][x] += 1
if array[y][x] == 3:
if adjcheck(x, y, array, rowsno, colsno):
changed[y][x] = 1
else:
changed[y][x] = 3
return changed