-
Notifications
You must be signed in to change notification settings - Fork 0
/
front_wave_map.py
101 lines (88 loc) · 3.15 KB
/
front_wave_map.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
import numpy as np
from colorama import Fore, Back, Style
map = np.array([[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1],
[1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1],
[1,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1],
[1,1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,1],
[1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,1],
[1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1],
[1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,1],
[1,1,0,0,1,0,1,0,1,0,1,1,1,1,1,1,1,0,1,1],
[1,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,1,1],
[1,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,1,1],
[1,1,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,0,1,1],
[1,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,1,1],
[1,1,0,0,1,0,0,0,0,0,0,0,0,1,1,0,1,0,1,1],
[1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0,1,0,1,1],
[1,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,0,1,1],
[1,1,0,1,0,1,0,1,0,0,1,1,1,0,1,0,1,0,1,1],
[1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]])
start = np.array([18, 1])
finish = np.array([2, 18])
for i in map:
for j in i:
if j == 1:
print(Back.WHITE + " " + str(j), end="")
else:
print(Back.BLACK + " " + str(j), end="")
print(Back.BLACK + "")
first_number = 2
def frontwave(xy, first_number):
if xy[0] < 0 or xy[0] > 19:
return 0
if xy[1] < 0 or xy[1] > 19:
return 0
if map[xy[0]][xy[1]] == 1:
return 0
if map[xy[0]][xy[1]] != 0:
return 0
if map[xy[0]][xy[1]] == 0:
map[xy[0]][xy[1]] = first_number
frontwave(np.array([xy[0], xy[1] + 1]), first_number + 1)
frontwave(np.array([xy[0], xy[1] - 1]), first_number + 1)
frontwave(np.array([xy[0] + 1, xy[1]]), first_number + 1)
frontwave(np.array([xy[0] - 1, xy[1]]), first_number + 1)
frontwave(finish, 2)
print("")
for i in map:
for j in i:
if j == 1:
print(Back.WHITE + " " + str(j), end="")
else:
if j < 10:
print(Back.BLACK + " " + str(j), end="")
elif j < 100:
print(Back.BLACK + "" + str(j), end="")
else:
print(Back.BLACK + "" + str(j), end="")
print(Back.BLACK + "")
x = start[0]
y = start[1]
way = [[x, y]]
while map[x][y] != 2:
if map[x + 1][y] < map[x][y] and map[x + 1][y] != 1:
x = x + 1
way.append([x, y])
continue
if map[x - 1][y] < map[x][y] and map[x - 1][y] != 1:
x = x - 1
way.append([x, y])
continue
if map[x][y + 1] < map[x][y] and map[x][y + 1] != 1:
y = y + 1
way.append([x, y])
continue
if map[x][y - 1] < map[x][y] and map[x][y - 1] != 1:
y = y - 1
way.append([x, y])
continue
print(way)
for elem in way:
elem[0] = -(elem[0]*2.5 + 1.25 - 25.57)
elem[1] = elem[1]*2.5 + 1.25 - 25.72
print("")
print(way)