-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaskii_word_maze.py
168 lines (148 loc) · 5.82 KB
/
askii_word_maze.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def add_line_to_lis(line, chr_number, alphabetic_mask):
temp_lis = []
for char in line:
if char == "X":
temp_lis.append(True)
elif char == "O":
temp_lis.append(False)
alphabetic_mask[chr(chr_number)].append(temp_lis)
# temp_lis = []
# for i in range(5):
# for i in range(3):
# temp_lis.append(False)
# alphabetic_mask[" "].append(temp_lis)
def make_empty_mask():
alphabetic_mask = {}
for i in range(97, 123):
alphabetic_mask[chr(i)] = []
alphabetic_mask[" "] = []
return alphabetic_mask
def make_alpha_mask():
alphabetic_mask = make_empty_mask()
with open("letters_askii.txt", "r") as f:
chr_number = 97 # a
for line in f:
line = line.strip()
if line == "":
if chr_number != 122:
chr_number += 1
else:
chr_number = 32
else:
add_line_to_lis(line, chr_number, alphabetic_mask)
return alphabetic_mask
def make_word_mask(alphabetic_mask, text):
text_lis = []
for i in range(5):
temp_lis = []
for letter in text:
temp_lis += alphabetic_mask[letter][i]
temp_lis += [False]
text_lis.append(temp_lis)
return text_lis
def make_top_line(text_lis):
ascii_str = ""
for x in range(len(text_lis[0])):
if text_lis[0][x] == False:
if x != len(text_lis[0]) - 1:
if x != 0:
ascii_str += " " if text_lis[0][x+1] == False else " "
else:
ascii_str += " "
else:
try:
if text_lis[0][x-1] == False:
ascii_str += u'╔═'
else:
ascii_str += u'╦═'
except:
ascii_str += u'╔═'
try:
if text_lis[0][x+1] == False:
ascii_str += u'╗'
except:
ascii_str += u'╗'
ascii_str += "\n"
return ascii_str
def make_askii_text(alphabetic_mask, text):
text_lis = make_word_mask(alphabetic_mask, text.lower())
ascii_str = make_top_line(text_lis)
for y in range(5):
try:
if text_lis[y+1][0] == False and text_lis[y][0] == False:
ascii_str += " "
elif text_lis[y][0] == True and text_lis[y+1][0] == True:
ascii_str += u'╠'
elif text_lis[y][0] == False and text_lis[y+1][0] == True:
ascii_str += u'╔'
else:
ascii_str += u'╚'
except:
if text_lis[y][0] == False:
ascii_str += " "
else:
ascii_str += u'╚'
for x in range(0, len(text_lis[0])):
try:
if text_lis[y][x] == True:
ascii_str += u'═'
elif text_lis[y][x] == False and text_lis[y+1][x] == False:
ascii_str += " "
else:
ascii_str += u'═'
except:
# y == 4
ascii_str += u'═' if text_lis[y][x] == True else " "
try:
if text_lis[y][x] == True and (text_lis[y+1][x+1] == True or (text_lis[y+1][x] == True and text_lis[y][x+1] == True)):
ascii_str += u'╬'
elif text_lis[y][x] == True and (text_lis[y][x+1] == True or text_lis[y+1][x+1] == True):
ascii_str += u'╩'
elif text_lis[y][x] == True and text_lis[y+1][x] == True:
ascii_str += u'╣'
elif text_lis[y][x] == True:
ascii_str += u'╝'
elif text_lis[y][x] == False and text_lis[y+1][x] == True and (text_lis[y][x+1] == True):
ascii_str += u'╬'
elif text_lis[y][x] == False and text_lis[y+1][x] == True and text_lis[y+1][x+1] == True:
ascii_str += u'╦'
elif text_lis[y][x] == False and text_lis[y][x+1] == True and text_lis[y+1][x+1] == True:
ascii_str += u'╠'
elif text_lis[y][x] == False and text_lis[y+1][x] == True:
ascii_str += u'╗'
elif text_lis[y][x] == False and text_lis[y][x+1] == True:
ascii_str += u'╚'
elif text_lis[y][x] == False and text_lis[y+1][x+1] == True:
ascii_str += u'╔'
else:
ascii_str += " "
except:
if y == 4 and x == len(text_lis[0]) - 1:
ascii_str += u'╝' if text_lis[y][x] else " "
elif y == 4:
if text_lis[y][x] == True and text_lis[y][x+1] == True:
ascii_str += u'╩'
elif text_lis[y][x] == True:
ascii_str += u'╝'
elif text_lis[y][x] == False and text_lis[y][x+1] == True:
ascii_str += u'╚'
else:
ascii_str += " "
elif x == len(text_lis[0]) - 1:
if text_lis[y][x] == True and text_lis[y+1][x] == True:
ascii_str += u'╣'
elif text_lis[y][x] == True:
ascii_str += u'╝'
elif text_lis[y][x] == False and text_lis[y+1][x] == True:
ascii_str += u'╗'
else:
ascii_str += " "
print(ascii_str)
ascii_str = ""
# ascii_str += "\n"
# print(ascii_str)
def main():
ascii_text = input("What to do you want ascii-fied: ")
alphabetic_mask = make_alpha_mask()
make_askii_text(alphabetic_mask, ascii_text)
main()