-
Notifications
You must be signed in to change notification settings - Fork 0
/
Neighbors.py
58 lines (49 loc) · 1.99 KB
/
Neighbors.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
57
58
""" la classe voisine permet de determiner pour les voisines
pour chaque cellule choisie vivante ou non
"""
class Neighbors:
def __init__(self, cellule, N_cellule):
self.cellule = cellule
self.N_cellule = N_cellule
self.x , self.y = cellule
# Check si le x est bon et le y
self.check_x = True if self.x < N_cellule and self.x >= 0 else False
self.check_y = True if self.y < N_cellule and self.y >= 0 else False
"""Voisine de Gauche"""
def neighbor_left_top(self):
if self.x-1 >= 0 and self.y-1 >=0:
return (self.x-1, self.y-1)
def neighbor_left_center(self):
if self.check_x and self.y-1 >=0:
return (self.x, self.y-1)
def neighbor_left_bottom(self):
if self.x+1 < self.N_cellule and self.y-1 >=0:
return (self.x+1, self.y-1)
"""Voisine de Centre"""
def neighbor_center_top(self):
if self.check_y and self.x-1 >=0:
return (self.x-1, self.y)
def neighbor_center_bottom(self):
if self.check_y and self.x+1 < self.N_cellule:
return (self.x+1, self.y)
"""Voisine de Droite"""
def neighbor_right_top(self):
if self.x-1 >=0 and self.y+1 < self.N_cellule:
return (self.x-1, self.y+1)
def neighbor_right_center(self):
if self.check_x and self.y+1 < self.N_cellule:
return (self.x, self.y+1)
def neighbor_right_bottom(self):
if self.x+1 < self.N_cellule and self.y+1 < self.N_cellule:
return (self.x+1, self.y+1)
def neighbor_list(self):
out = []
out.append(self.neighbor_left_top())
out.append(self.neighbor_left_center())
out.append(self.neighbor_left_bottom())
out.append(self.neighbor_center_top())
out.append(self.neighbor_center_bottom())
out.append(self.neighbor_right_top())
out.append(self.neighbor_right_center())
out.append(self.neighbor_right_bottom())
return out