-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue.py
More file actions
167 lines (120 loc) · 4.19 KB
/
Copy pathvalue.py
File metadata and controls
167 lines (120 loc) · 4.19 KB
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
from string import ascii_uppercase
# setter for variables
def set(array, value):
is_player_var = (array.string == "player variable")
if is_player_var:
return set_player_variable(array.args[0], array.args[1], value)
else:
return set_global_variable(array.args[0], value)
def modify(array, operation, value):
is_player_var = (array.string == "player variable")
if is_player_var:
return modify_player_variable(array.args[0], array.args[1], operation, value)
else:
return modify_global_variable(array.args[0], operation, value)
# setter for arrays
def set_at_index(array, index, value):
is_player_var = (array.string == "player variable")
if is_player_var:
return set_player_variable_at_index(array.args[0], array.args[1], index, value)
else:
return set_global_variable_at_index(array.args[0], index, value)
def modify_at_index(array, index, operation, value):
is_player_var = (array.string == "player variable")
if is_player_var:
return modify_player_variable_at_index(array.args[0], array.args[1], index, operation, value)
else:
return modify_global_variable_at_index(array.args[0], index, operation, value)
# all values and actions are instances of this bad boy
# this class contains ALL the overloads humanly imaginable
class Value:
def __init__(self, input_string, type = "any", args = None):
self.string = input_string
self.args = args if args is not None else []
self.type = type
# player variables
if self.type == "player":
for var in ascii_uppercase:
setattr(self, var, Value("player variable", "base", [ self, var ]))
# serialize
def __str__(self):
return self.string + ("(" + ", ".join([ str(arg) for arg in self.args ]) + ")" if len(self.args) > 0 else "")
# comparison operations
def __lt__(self, other):
return compare(self, less_than, other)
def __le__(self, other):
return compare(self, less_or_equal, other)
def __eq__(self, other):
return compare(self, equal, other)
def __ne__(self, other):
return compare(self, not_equal, other)
def __gt__(self, other):
return compare(self, greater_than, other)
def __ge__(self, other):
return compare(self, greater_or_equal, other)
# mathematical or bitwise operations
def __abs__(self):
return absolute_value(self)
def __add__(self, other):
return add(self, other)
def __and__(self, other):
return _and(self, other)
def __floordiv__(self, other):
return round_to_integer(divide(self, other), down)
def __invert__(self):
return _not(self)
def __matmul__(self, other):
return dot_product(self, other)
def __mod__(self, other):
return modulo(self, other)
def __mul__(self, other):
return multiply(self, other)
def __neg__(self):
return multiply(self, number(-1))
def __or__(self, other):
return _or(self, other)
def __pos__(self):
return absolute_value(self)
def __pow__(self, other):
return raise_to_power(self, other)
def __sub__(self, other):
return subtract(self, other)
def __truediv__(self, other):
return divide(self, other)
def __xor__(self, other):
return _and(_not(_and(self, other)), _or(self, other))
# right hand side operations
def __radd__(self, other):
return add(other, self)
def __rsub__(self, other):
return subtract(other, self)
def __rmatmul__(self, other):
return dot_product(other, self)
def __rmul__(self, other):
return multiply(other, self)
def __rtruediv__(self, other):
return divide(other, self)
def __floordiv__(self, other):
return round_to_integer(divide(other, self), down)
def __rmod__(self, other):
return modulo(other, self)
def __rpow__(self, other):
return raise_to_power(other, self)
def __rand__(self, other):
return _and(other, self)
def __rxor__(self, other):
return _and(_not(_and(other, self)), _or(other, self))
def __ror__(self, other):
return _or(other, self)
# array operations
def __contains__(array, value):
return array_contains(array, value)
def countOf(array, value):
return count_of(array, value)
def __getitem__(array, index):
if isinstance(index, slice):
return array_slice(array, index.start, index.stop)
else:
return value_in_array(array, index)
def indexOf(array, value):
return index_of_array_value(array, value)