-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarehouse.py
104 lines (83 loc) · 3.11 KB
/
warehouse.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/bash
# -*- coding: utf-8 -*
class Warehouse:
matrix = None
WIDTH = 101 #zrobilem na razie 101 x 101, bo nie chcialem bawic w ograniczanie funkcji do poruszania sie
HEIGHT = 101 #zeby uniknac wychodzenia poza zakres
entrance = None
index_x = 50
index_y = 50
first = True
def __init__(self):
self.matrix = [[0 for x in range(self.WIDTH)] for y in range(self.HEIGHT)]
self.init_matrix()
def init_matrix(self):
for j in range(self.WIDTH):
for i in range(self.HEIGHT):
self.matrix[i][j] = -3
def set_way_on_matrix_when_moving_up(self):
for i in range(5):
self.matrix[self.index_x - i][self.index_y] = -2
if self.first is True:
self.matrix[self.index_x][self.index_y] = -1
self.first = False
self.index_x -= 5
def set_way_on_matrix_when_moving_down(self):
for i in range(5):
self.matrix[self.index_x + i][self.index_y] = -2
if self.first is True:
self.matrix[self.index_x][self.index_y] = -1
self.first = False
self.index_x += 5
def set_way_on_matrix_when_moving_left(self):
for i in range(5):
self.matrix[self.index_x][self.index_y - i] = -2
if self.first is True:
self.matrix[self.index_x][self.index_y] = -1
self.first = False
self.index_y -= 5
def set_way_on_matrix_when_moving_right(self):
for i in range(5):
self.matrix[self.index_x][self.index_y + i] = -2
if self.first is True:
self.matrix[self.index_x][self.index_y] = -1
self.first = False
self.index_y += 5
def fill_warehouse(self):
#self.fill_field(49, 50) hardcoded, wystarczy podac jakis punkt wewnatrz magazynu
self.fill_field(49, 50)
self.debug_warehouse_shape()
#self.debug()
def fill_field(self, x, y):
if x > 99 or y > 99 or x < 0 or y < 0 or self.matrix[x][y] == -2 \
or self.matrix[x][y] == 0 or self.matrix[x][y] == -1:
return
elif self.matrix[x][y] == -3:
self.matrix[x][y] = 0
self.fill_field(x-1, y)
self.fill_field(x, y+1)
self.fill_field(x+1, y)
self.fill_field(x, y-1)
def debug_warehouse_shape(self):
counter = 0
for x in range(self.HEIGHT):
y = 0
while y < self.WIDTH:
if self.matrix[x][y] == 0:
counter += 1
print("x", end=" ")
elif self.matrix[x][y] >= 10:
print("o", end=" ")
elif self.matrix[x][y] > 0:
print(self.matrix[x][y], end=" ")
elif self.matrix[x][y] == -1:
print("_", end=" ")
elif self.matrix[x][y] == -3:
print("a", end=" ")
elif self.matrix[x][y] <= -4:
print("b", end=" ")
else:
print(" ", end=" ")
y += 1
print("")
print(counter)