-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_tree.py
100 lines (91 loc) · 4.51 KB
/
decode_tree.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
class Node:
def __init__(self, value, dot=None, dash=None):
self.value = value
self.dot = dot
self.dash = dash
self.oval = None
self.line = None
class DecodeTree:
def __init__(self):
self.root_node = Node("",
Node("E",
Node("I",
Node("S",
Node("H",
Node("5"),
Node("4")),
Node("V",
None,
Node("3"))),
Node("U",
Node("F"),
Node("",
Node("",
Node("?"),
Node("-")),
Node("2")))),
Node("A",
Node("R",
Node("L"),
Node("",
Node("+",
None,
Node(".")))),
Node("W",
Node("P",
None,
Node("",
Node("@"))),
Node("J",
None,
Node("1"))))),
Node("T",
Node("N",
Node("D",
Node("B",
Node("6",
None,
Node("-")),
Node("=")),
Node("X",
Node("/"))),
Node("K",
Node("C",
None,
Node("",
Node(";"))),
Node("Y",
Node("(",
None,
Node(")"))))),
Node("M",
Node("G",
Node("Z",
Node("7"),
Node("",
None,
Node(","))),
Node("Q")),
Node("O",
Node("",
Node("8",
Node(":"))),
Node("",
Node("9"),
Node("0"))))))
self.current_node = self.root_node
def reset(self):
self.current_node = self.root_node
def dash(self):
if self.current_node and self.current_node.dash:
self.current_node = self.current_node.dash
def dot(self):
if self.current_node and self.current_node.dot:
self.current_node = self.current_node.dot
def is_char_available(self):
return self.current_node != self.root_node
def current_char(self):
if self.current_node and self.current_node.value:
return self.current_node.value
else:
return None