-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.py
103 lines (75 loc) · 3.87 KB
/
text.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
from bfs import bfs
import map
map_graph = dict(
map.East_1,**map.East_2,**map.East_3,**map.East_4,**map.East_5,
**map.North_1,**map.North_2,**map.North_3,**map.North_4,**map.North_5,
**map.West_2,**map.West_3,**map.West_4,**map.West_5,
**map.South_1,**map.South_2,**map.South_3,**map.South_4,**map.South_5,
**map.Stair
)
def get_map_graph():
return map_graph
def convert_text(text):
direction_index = 1
text_direction = text[direction_index]
conversion_target = {
"동":"E","서":"W","남":"S","북":"N",
"e":"E","w":"W","s":"S","n":"N"
}
if text_direction_is_conversion_target(text_direction, conversion_target):
direction_converted_text = text[0] + conversion_target[text_direction] + text[2:]
return direction_converted_text
else:
return text
def text_direction_is_conversion_target(text_direction, conversion_target):
return text_direction in conversion_target
def map_text(start, finish):
route = bfs(map_graph,start,finish)
result = []
direction = {"E":"동","W":"서","S":"남","N":"북"}
direction_index = 1
floor_index = 2
for idx, i in enumerate(route):
if current_node_is_start_of_route(idx):
result.append(f'5호관 {route[0]}에서 {route[direction_index]}쪽 방향으로 출발')
elif current_node_is_stair(i):
if current_node_is_elevator(i):
result.append(f'{i}를 통해 {route[idx-1][floor_index]}층에서 {route[idx+1][floor_index]}층으로 이동하여 {route[idx+1]}까지 이동')
elif node_is_5s_connection_stair(i):
if route[idx-1][2] == route[idx+1][2]:
result.append(f'{i}을 통해 {route[idx-1]}에서 {route[idx+1]}까지 이동 (왼쪽 계단 1번 → 오른쪽 계단 1번)')
else:
result.append(f'{i}을 통해 {route[idx-1][floor_index]}층에서 {route[idx+1][floor_index]}층으로 이동하여 {route[idx+1]}까지 이동')
else:
result.append(f'{i}을 통해 {route[idx-1][floor_index]}층에서 {route[idx+1][floor_index]}층으로 이동하여 {route[idx+1]}까지 이동')
if idx + 2 < len(route) and route[idx+1][1] == route[idx+2][1]:
result.append(f'{route[idx+1]}에서 {route[idx+2]} 방향으로 이동')
else:
if not current_node_is_end_of_route(route,idx):
if next_node_is_not_stair(route, idx):
if current_direction_and_next_direction_are_different(route, idx):
result.append(f'{i}까지 이동 후 {direction[route[idx][direction_index]]}쪽 건물에서 {direction[route[idx+1][direction_index]]}쪽 건물로 이동하여 {route[idx+1]}까지 이동')
result.append(f'{route[idx+1]}에서 {route[idx+2]} 방향으로 이동')
elif current_node_is_end_of_route(route, idx):
result.append(f'{i}까지 이동하여 도착')
else:
if not current_node_is_end_of_route(route,idx) and next_node_is_stair(route, idx):
result.append(f'5호관 {i} 옆 {route[idx+1]}까지 이동')
return result
def current_node_is_elevator(i):
return "엘리베이터" in i
def next_node_is_stair(route, idx):
return "계단" in route[idx+1]
def current_direction_and_next_direction_are_different(route, idx):
direction_index = 1
return route[idx][direction_index] != route[idx+1][direction_index]
def next_node_is_not_stair(route, idx):
return not "계단" in route[idx+1]
def current_node_is_end_of_route(route, idx):
return idx == len(route) - 1
def current_node_is_stair(i):
return "계단" in i
def current_node_is_start_of_route(idx):
return idx == 0
def node_is_5s_connection_stair(node):
return "5남의 동쪽과 서쪽을 이어주는 계단" == node