-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadapter_task.py
74 lines (55 loc) · 1.9 KB
/
adapter_task.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from abc import ABC, abstractmethod
class System:
def __init__(self):
self.map = self.grid = [[0 for i in range(30)] for _ in range(20)]
self.map[5][7] = 1 # Источник света
self.map[5][2] = -1 # Стены
def get_lightening(self, light_mapper):
lightmap = light_mapper.lighten(self.map)
return lightmap
class Light:
def __init__(self, dim):
self.dim = dim
self.grid = [[0 for i in range(dim[0])] for _ in range(dim[1])]
self.lights = []
self.obstacles = []
def set_dim(self, dim):
self.dim = dim
self.grid = [[0 for i in range(dim[0])] for _ in range(dim[1])]
def set_lights(self, lights):
self.lights = lights
self.generate_lights()
def set_obstacles(self, obstacles):
self.obstacles = obstacles
self.generate_lights()
def generate_lights(self):
return self.grid.copy()
class LightProcessor:
@abstractmethod
def lighten(self, my_map):
pass
class MappingAdapter(LightProcessor):
def __init__(self, adaptee):
self.adaptee = adaptee
def lighten(self, my_map):
dim = tuple(input('Enter dim:'))
obstacles = []
lights = []
my_grid = [[0 for i in range(int(dim[0]))] for _ in range(int(dim[1]))]
for i in range(len(my_map)):
for j in range(len(my_map[i])):
if my_map[i][j] == 1:
lights.append([i, j])
if my_map[i][j] == -1:
obstacles.append([i, j])
if my_map[i][j] == 0:
my_map[i][j] = 's'
print(my_map.copy(), lights.copy(), obstacles.copy(), my_grid.copy())
def main():
dim = [5, 5]
system = System()
light = Light(dim)
light_adapter = MappingAdapter(light)
print(system.get_lightening(light_adapter))
if __name__ == '__main__':
main()