1import math
2import copy
3
4#написано до Преходност
5#done except tick()
6
7class Potion:
8
9 def __init__(self, effects : dict, duration : int) -> None:
10 self.effects = effects
11 self.duration = duration
12 self.used_effects = set()
13 self.potency = dict.fromkeys(effects, 1)
14 self.used = False
15
16 def __getattr__(self, name : str):
17 if name in self.effects:
18 if name not in self.used_effects:
19 self.used_effects .add(name)
20 return self.__apply_potency__(name)
21 else:
22 raise TypeError("Effect is depleted.")
23
24 def __add__(self, other):
25 if self.used:
26 raise TypeError("Potion is now part of something bigger than itself.")
27
28 self.used_effects .update(other.used)
29 self.duration = max(self.duration, other.duration)
30 for effect in other.effects:
31 if effect in self.effects:
32 self.potency[effect] += other.potency[effect]
33 else:
34 self.effects[effect] = other.effects[effect]
35
36 self.used = True
37 return self
38
39 def __sub__(self, other):
40 if self.used:
41 raise TypeError("Potion is now part of something bigger than itself.")
42
43 self.used_effects .difference(other.used)
44 for effect in other.effects:
45 if effect in self.effects:
46 self.potency[effect] -= other.potency[effect]
47 else:
48 raise TypeError(f"Effect \"{effect}\" not present.")
49
50 self.__delete_removed_effects__()
51
52 self.used = True
53 return self
54
55 def __mul__(self, number):
56 if self.used:
57 raise TypeError("Potion is now part of something bigger than itself.")
58
59 for effect in self.potency:
60 self.potency[effect] *= number
61 if (self.potency[effect] - math.floor(self.potency[effect])) > 0.5:
62 self.potency[effect] = math.ceil(self.potency[effect])
63 else:
64 self.potency[effect] = math.floor(self.potency[effect])
65
66 self.__delete_removed_effects__()
67
68 self.used = True
69 return self
70
71 def __truediv__ (self, number : int):
72 if self.used:
73 raise TypeError("Potion is now part of something bigger than itself.")
74
75 temp_potion = Potion(effects=self.effects, duration=self.duration)
76 temp_potion.potency = self.potency
77 temp_potion = temp_potion * (1 / number)
78 temp_potion.__delete_removed_effects__()
79
80 self.used = True
81 return [temp_potion for _ in range(number)]
82
83 def __eq__(self, other: object) -> bool:
84 if self.__total_potency__() != other.__total_potency__():
85 return False
86
87 return self.__compare__effects__(other)
88
89 def __lt__(self, other: object) -> bool:
90 return self.__total_potency__() < other.__total_potency__()
91
92 def __rt__(self, other: object) -> bool:
93 return self.__total_potency__() > other.__total_potency__()
94
95 def __apply_potency__(self, name):
96 def apply_potion(target):
97 for _ in range(self.potency[name]):
98 self.effects[name](target)
99 #return target
100 return apply_potion
101
102 def __delete_removed_effects__(self) -> None:
103 #self.effects = {effect:self.effects[effects] for effect in self.effects if self.potency[effect] > 0}
104 #self.potency = {effect:self.potency[effects] for effect in self.potency if effect in self.effect}
105
106 for effect in self.potency:
107 if self.potency[effect] <= 0:
108 self.effects.pop(effect)
109 self.potency[effect] = 0
110
111 self.potency = {effect:self.potency[effect] for effect in self.effects}
112
113 def __total_potency__(self) -> int:
114 return sum([self.potency[effect] for effect in self.potency])
115
116 def __compare__effects__(self, __other):
117 for effect in self.effects:
118 if effect not in __other.effects:
119 return False
120
121 return True
122
123def calculate_molecular_mass(name : str) -> int:
124 return sum(ord(symbol) for symbol in name)
125
126class ГоспожатаПоХимия:
127
128 def __init__(self) -> None:
129 self.potion_effects = dict()
130 self.original_targets = dict()
131 self.affected_targets = set()
132
133 def apply(self, target, potion : Potion) -> None:
134 if potion.used:
135 raise TypeError("Potion is depleted.")
136
137 self.affected_targets.add(target)
138 original_target = copy.deepcopy(target)
139 self.original_targets[id(target)] = original_target
140 if id(target) not in self.potion_effects:
141 self.potion_effects[id(target)] = [potion]
142 else:
143 self.potion_effects[id(target)].append(potion)
144
145 for effect in potion.effects:
146 potion.effects[effect](target)
147
148 potion.used = True
149
150 def tick(self) -> None:
151 for target in self.affected_targets:
152 flag = False
153 for potion in self.potion_effects[id(target)]:
154 if potion.duration > 0:
155 potion.duration -= 1
156 else:
157 flag = True
158 if flag:
159 self.potion_effects[id(target)] = [potion for potion in self.potion_effects[id(target)] if potion.duration > 0]
160 temp_target = copy.deepcopy(self.original_targets[id(target)])
161 for potion in self.potion_effects[id(target)]:
162 potion.used = False
163 self.apply(temp_target, potion)
164 target = temp_target
165
166
167
168
169"""
170
171effects = {'grow': lambda target: setattr(target, 'size', target.size*2)}
172
173class Target:
174
175 def __init__(self) -> None:
176 self.size = 5
177
178class TestTarget:
179 def __init__(self, x , y, size) -> None:
180 self.x = x
181 self.y = y
182 self.size = size
183
184target = Target()
185
186grow = Potion(effects=effects, duration=3)
187print(target.size)
188narco = ГоспожатаПоХимия()
189narco.apply(target, grow)
190
191print(target.size)
192narco.tick()
193print(target.size)
194narco.tick()
195print(target.size)
196narco.tick()
197print(target.size)
198narco.tick()
199print(target.size)
200narco.tick()
201print(target.size)
202
203
204teleport_potion
205combined_potion = teleport_potion + grow_potion
206
207target = TestTarget(1, 1, 1)
208
209combined_potion.teleport(target)
210combined_potion.grow(target)
211
212"""
213
214#target.size = 5
215#grow = Potion(effects=effects, duration=2) * 3
216#grow.grow(target)
217#print(target.size)
218
219#target.size = 5
220#grow = Potion(effects=effects, duration=2) * 3
221#grow = grow * 0.33
222#grow.grow(target)
223#print(target.size)
224
225#target.size = 5
226#grow = Potion(effects=effects, duration=2) * 3
227#grow = grow - Potion(effects=effects, duration=2)
228#grow = grow - Potion(effects=effects, duration=2)
229#grow = grow - Potion(effects=effects, duration=2)
230#grow.grow(target)
231#print(target.size)
232
233
234#grow = Potion(effects=effects, duration=2)
235#grow.potency["grow"] = 4
236
237#small_grow ,_= grow / 2
238#small_grow.grow(target)
239#print(target.size)
240
241#grow = Potion(effects=effects, duration=2)
242#grow2 = Potion(effects=effects, duration=2)
243#grow2.potency["grow"] = 1
244#print(grow == grow2)
245
246
247#d = { "d":3454, "22":3456, "agds":5345, "A":456, "X":4567, "CCCCCCCCCCCCCCCCCCC":56}
248#d={k:d[k] for k in sorted(d,key=calculate_molecular_mass)}
249#print(d)
250
251#target = Target()
252#target2 = copy.copy(target)
253#print(target.size, target2.size)
254#target2.size = 10
255#print(target.size, target2.size)
...E.EEEE.EEF.FFEFEF
======================================================================
ERROR: test_equal (test.TestPotionComparison)
Test equality of potions.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 292, in test_equal
self.assertEqual(potion1 + potion2, potion3)
File "/tmp/solution.py", line 28, in __add__
self.used_effects .update(other.used)
TypeError: 'bool' object is not iterable
======================================================================
ERROR: test_combination_no_overlap (test.TestPotionOperations)
Test combining potions with no overlap.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 93, in test_combination_no_overlap
potion = potion1 + potion2
File "/tmp/solution.py", line 28, in __add__
self.used_effects .update(other.used)
TypeError: 'bool' object is not iterable
======================================================================
ERROR: test_combination_with_overlap (test.TestPotionOperations)
Test combining potions with overlap.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 103, in test_combination_with_overlap
potion = potion1 + potion2
File "/tmp/solution.py", line 28, in __add__
self.used_effects .update(other.used)
TypeError: 'bool' object is not iterable
======================================================================
ERROR: test_deprecation (test.TestPotionOperations)
Test deprecation of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 256, in test_deprecation
potion = potion1 + potion2
File "/tmp/solution.py", line 28, in __add__
self.used_effects .update(other.used)
TypeError: 'bool' object is not iterable
======================================================================
ERROR: test_dilution (test.TestPotionOperations)
Test dilution of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 119, in test_dilution
half_potion.int_attr_fun(self._target)
TypeError: 'NoneType' object is not callable
======================================================================
ERROR: test_purification (test.TestPotionOperations)
Test purification of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 165, in test_purification
potion = potion1 - potion2
File "/tmp/solution.py", line 43, in __sub__
self.used_effects .difference(other.used)
TypeError: 'bool' object is not iterable
======================================================================
ERROR: test_separation (test.TestPotionOperations)
Test separation of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 213, in test_separation
potion1, potion2, potion3 = potion / 3
File "/tmp/solution.py", line 73, in __truediv__
raise TypeError("Potion is now part of something bigger than itself.")
TypeError: Potion is now part of something bigger than itself.
======================================================================
ERROR: test_ticking_immutable (test.TestГоспожатаПоХимия)
Test ticking after applying a potion with immutable attributes.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 423, in test_ticking_immutable
potion = potion1 + potion2 # Excepted duration is 2 with intensity of 2
File "/tmp/solution.py", line 28, in __add__
self.used_effects .update(other.used)
TypeError: 'bool' object is not iterable
======================================================================
ERROR: test_ticking_multiple_targets (test.TestГоспожатаПоХимия)
Test ticking after applying a potion with mutable attributes.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 485, in test_ticking_multiple_targets
self._dimitrichka.apply(target1, potion1)
File "/tmp/solution.py", line 135, in apply
raise TypeError("Potion is depleted.")
TypeError: Potion is depleted.
======================================================================
FAIL: test_applying_depleted_potion (test.TestГоспожатаПоХимия)
Test applying a depleted potion or a potion that was used in a reaction.
----------------------------------------------------------------------
TypeError: Potion is now part of something bigger than itself.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/test.py", line 382, in test_applying_depleted_potion
with self.assertRaisesRegex(TypeError, 'Potion is depleted\.'):
AssertionError: "Potion is depleted\." does not match "Potion is now part of something bigger than itself."
======================================================================
FAIL: test_applying_order (test.TestГоспожатаПоХимия)
Test applying order of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 405, in test_applying_order
self.assertEqual(self._target.int_attr, 12)
AssertionError: 14 != 12
======================================================================
FAIL: test_applying_part_of_potion (test.TestГоспожатаПоХимия)
Test applying only a part of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 366, in test_applying_part_of_potion
self.assertEqual(self._target.int_attr, 5) # This should be the original value
AssertionError: 50 != 5
======================================================================
FAIL: test_ticking_multiple_potions (test.TestГоспожатаПоХимия)
Test ticking after applying multiple potions which affect the same attribute.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 458, in test_ticking_multiple_potions
self.assertEqual(self._target.int_attr, 50)
AssertionError: 500 != 50
======================================================================
FAIL: test_ticking_mutable (test.TestГоспожатаПоХимия)
Test ticking after applying a potion with mutable attributes.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 444, in test_ticking_mutable
self.assertEqual(self._target.int_attr, 5)
AssertionError: 50 != 5
----------------------------------------------------------------------
Ran 20 tests in 0.002s
FAILED (failures=5, errors=9)
| n | 1 | from typing import Any | n | ||
| 2 | import math | 1 | import math | ||
| 3 | import copy | 2 | import copy | ||
| 4 | 3 | ||||
| 5 | #написано до Преходност | 4 | #написано до Преходност | ||
| 6 | #done except tick() | 5 | #done except tick() | ||
| 7 | 6 | ||||
| 8 | class Potion: | 7 | class Potion: | ||
| 9 | 8 | ||||
| 10 | def __init__(self, effects : dict, duration : int) -> None: | 9 | def __init__(self, effects : dict, duration : int) -> None: | ||
| 11 | self.effects = effects | 10 | self.effects = effects | ||
| 12 | self.duration = duration | 11 | self.duration = duration | ||
| 13 | self.used_effects = set() | 12 | self.used_effects = set() | ||
| 14 | self.potency = dict.fromkeys(effects, 1) | 13 | self.potency = dict.fromkeys(effects, 1) | ||
| 15 | self.used = False | 14 | self.used = False | ||
| 16 | 15 | ||||
| n | 17 | def __getattr__(self, __name : str) -> Any: | n | 16 | def __getattr__(self, name : str): |
| 18 | if __name in self.effects: | 17 | if name in self.effects: | ||
| 19 | if __name not in self.used_effects : | 18 | if name not in self.used_effects: | ||
| 20 | self.used_effects .add(__name) | 19 | self.used_effects .add(name) | ||
| 21 | return self.__apply_potency__(__name) | 20 | return self.__apply_potency__(name) | ||
| 22 | else: | 21 | else: | ||
| 23 | raise TypeError("Effect is depleted.") | 22 | raise TypeError("Effect is depleted.") | ||
| 24 | 23 | ||||
| n | 25 | def __add__(self, __other) -> Any: | n | 24 | def __add__(self, other): |
| 26 | if self.used: | 25 | if self.used: | ||
| 27 | raise TypeError("Potion is now part of something bigger than itself.") | 26 | raise TypeError("Potion is now part of something bigger than itself.") | ||
| 28 | 27 | ||||
| n | 29 | self.used_effects .update(__other.used) | n | 28 | self.used_effects .update(other.used) |
| 30 | self.duration = max(self.duration, __other.duration) | 29 | self.duration = max(self.duration, other.duration) | ||
| 31 | for effect in __other.effects: | 30 | for effect in other.effects: | ||
| 32 | if effect in self.effects: | 31 | if effect in self.effects: | ||
| n | 33 | self.potency[effect] += __other.potency[effect] | n | 32 | self.potency[effect] += other.potency[effect] |
| 34 | else: | 33 | else: | ||
| n | 35 | self.effects[effect] = __other.effects[effect] | n | 34 | self.effects[effect] = other.effects[effect] |
| 36 | 35 | ||||
| 37 | self.used = True | 36 | self.used = True | ||
| 38 | return self | 37 | return self | ||
| 39 | 38 | ||||
| n | 40 | def __sub__(self, __other) -> Any: | n | 39 | def __sub__(self, other): |
| 41 | if self.used: | 40 | if self.used: | ||
| 42 | raise TypeError("Potion is now part of something bigger than itself.") | 41 | raise TypeError("Potion is now part of something bigger than itself.") | ||
| 43 | 42 | ||||
| n | 44 | self.used_effects .difference(__other.used) | n | 43 | self.used_effects .difference(other.used) |
| 45 | for effect in __other.effects: | 44 | for effect in other.effects: | ||
| 46 | if effect in self.effects: | 45 | if effect in self.effects: | ||
| n | 47 | self.potency[effect] -= __other.potency[effect] | n | 46 | self.potency[effect] -= other.potency[effect] |
| 48 | else: | 47 | else: | ||
| 49 | raise TypeError(f"Effect \"{effect}\" not present.") | 48 | raise TypeError(f"Effect \"{effect}\" not present.") | ||
| 50 | 49 | ||||
| 51 | self.__delete_removed_effects__() | 50 | self.__delete_removed_effects__() | ||
| 52 | 51 | ||||
| 53 | self.used = True | 52 | self.used = True | ||
| 54 | return self | 53 | return self | ||
| 55 | 54 | ||||
| n | 56 | def __mul__(self, __number) -> Any: | n | 55 | def __mul__(self, number): |
| 57 | if self.used: | 56 | if self.used: | ||
| 58 | raise TypeError("Potion is now part of something bigger than itself.") | 57 | raise TypeError("Potion is now part of something bigger than itself.") | ||
| 59 | 58 | ||||
| 60 | for effect in self.potency: | 59 | for effect in self.potency: | ||
| n | 61 | self.potency[effect] *= __number | n | 60 | self.potency[effect] *= number |
| 62 | if (self.potency[effect] - math.floor(self.potency[effect])) > 0.5: | 61 | if (self.potency[effect] - math.floor(self.potency[effect])) > 0.5: | ||
| 63 | self.potency[effect] = math.ceil(self.potency[effect]) | 62 | self.potency[effect] = math.ceil(self.potency[effect]) | ||
| 64 | else: | 63 | else: | ||
| 65 | self.potency[effect] = math.floor(self.potency[effect]) | 64 | self.potency[effect] = math.floor(self.potency[effect]) | ||
| 66 | 65 | ||||
| 67 | self.__delete_removed_effects__() | 66 | self.__delete_removed_effects__() | ||
| 68 | 67 | ||||
| 69 | self.used = True | 68 | self.used = True | ||
| 70 | return self | 69 | return self | ||
| 71 | 70 | ||||
| n | 72 | def __truediv__ (self, __number : int) -> Any: | n | 71 | def __truediv__ (self, number : int): |
| 73 | if self.used: | 72 | if self.used: | ||
| 74 | raise TypeError("Potion is now part of something bigger than itself.") | 73 | raise TypeError("Potion is now part of something bigger than itself.") | ||
| 75 | 74 | ||||
| 76 | temp_potion = Potion(effects=self.effects, duration=self.duration) | 75 | temp_potion = Potion(effects=self.effects, duration=self.duration) | ||
| 77 | temp_potion.potency = self.potency | 76 | temp_potion.potency = self.potency | ||
| n | 78 | temp_potion = temp_potion * (1 / __number) | n | 77 | temp_potion = temp_potion * (1 / number) |
| 79 | temp_potion.__delete_removed_effects__() | 78 | temp_potion.__delete_removed_effects__() | ||
| 80 | 79 | ||||
| 81 | self.used = True | 80 | self.used = True | ||
| n | 82 | return [temp_potion for _ in range(__number)] | n | 81 | return [temp_potion for _ in range(number)] |
| 83 | 82 | ||||
| n | 84 | def __eq__(self, __other: object) -> bool: | n | 83 | def __eq__(self, other: object) -> bool: |
| 85 | if self.__total_potency__() != __other.__total_potency__(): | 84 | if self.__total_potency__() != other.__total_potency__(): | ||
| 86 | return False | 85 | return False | ||
| 87 | 86 | ||||
| n | 88 | return self.__compare__effects__(__other) | n | 87 | return self.__compare__effects__(other) |
| 89 | 88 | ||||
| n | 90 | def __lt__(self, __other: object) -> bool: | n | 89 | def __lt__(self, other: object) -> bool: |
| 91 | return self.__total_potency__() < __other.__total_potency__() | 90 | return self.__total_potency__() < other.__total_potency__() | ||
| 92 | 91 | ||||
| n | 93 | def __rt__(self, __other: object) -> bool: | n | 92 | def __rt__(self, other: object) -> bool: |
| 94 | return self.__total_potency__() > __other.__total_potency__() | 93 | return self.__total_potency__() > other.__total_potency__() | ||
| 95 | 94 | ||||
| n | 96 | def __apply_potency__(self, __name) -> Any: | n | 95 | def __apply_potency__(self, name): |
| 97 | def apply_potion(target) -> Any: | 96 | def apply_potion(target): | ||
| 98 | for _ in range(self.potency[__name]): | 97 | for _ in range(self.potency[name]): | ||
| 99 | self.effects[__name](target) | 98 | self.effects[name](target) | ||
| 100 | #return target | 99 | #return target | ||
| 101 | return apply_potion | 100 | return apply_potion | ||
| 102 | 101 | ||||
| 103 | def __delete_removed_effects__(self) -> None: | 102 | def __delete_removed_effects__(self) -> None: | ||
| 104 | #self.effects = {effect:self.effects[effects] for effect in self.effects if self.potency[effect] > 0} | 103 | #self.effects = {effect:self.effects[effects] for effect in self.effects if self.potency[effect] > 0} | ||
| 105 | #self.potency = {effect:self.potency[effects] for effect in self.potency if effect in self.effect} | 104 | #self.potency = {effect:self.potency[effects] for effect in self.potency if effect in self.effect} | ||
| 106 | 105 | ||||
| 107 | for effect in self.potency: | 106 | for effect in self.potency: | ||
| 108 | if self.potency[effect] <= 0: | 107 | if self.potency[effect] <= 0: | ||
| 109 | self.effects.pop(effect) | 108 | self.effects.pop(effect) | ||
| 110 | self.potency[effect] = 0 | 109 | self.potency[effect] = 0 | ||
| 111 | 110 | ||||
| 112 | self.potency = {effect:self.potency[effect] for effect in self.effects} | 111 | self.potency = {effect:self.potency[effect] for effect in self.effects} | ||
| 113 | 112 | ||||
| 114 | def __total_potency__(self) -> int: | 113 | def __total_potency__(self) -> int: | ||
| 115 | return sum([self.potency[effect] for effect in self.potency]) | 114 | return sum([self.potency[effect] for effect in self.potency]) | ||
| 116 | 115 | ||||
| 117 | def __compare__effects__(self, __other): | 116 | def __compare__effects__(self, __other): | ||
| 118 | for effect in self.effects: | 117 | for effect in self.effects: | ||
| 119 | if effect not in __other.effects: | 118 | if effect not in __other.effects: | ||
| 120 | return False | 119 | return False | ||
| 121 | 120 | ||||
| 122 | return True | 121 | return True | ||
| 123 | 122 | ||||
| 124 | def calculate_molecular_mass(name : str) -> int: | 123 | def calculate_molecular_mass(name : str) -> int: | ||
| 125 | return sum(ord(symbol) for symbol in name) | 124 | return sum(ord(symbol) for symbol in name) | ||
| 126 | 125 | ||||
| 127 | class ГоспожатаПоХимия: | 126 | class ГоспожатаПоХимия: | ||
| 128 | 127 | ||||
| 129 | def __init__(self) -> None: | 128 | def __init__(self) -> None: | ||
| 130 | self.potion_effects = dict() | 129 | self.potion_effects = dict() | ||
| 131 | self.original_targets = dict() | 130 | self.original_targets = dict() | ||
| 132 | self.affected_targets = set() | 131 | self.affected_targets = set() | ||
| n | 133 | pass | n | ||
| 134 | 132 | ||||
| 135 | def apply(self, target, potion : Potion) -> None: | 133 | def apply(self, target, potion : Potion) -> None: | ||
| 136 | if potion.used: | 134 | if potion.used: | ||
| 137 | raise TypeError("Potion is depleted.") | 135 | raise TypeError("Potion is depleted.") | ||
| 138 | 136 | ||||
| 139 | self.affected_targets.add(target) | 137 | self.affected_targets.add(target) | ||
| 140 | original_target = copy.deepcopy(target) | 138 | original_target = copy.deepcopy(target) | ||
| 141 | self.original_targets[id(target)] = original_target | 139 | self.original_targets[id(target)] = original_target | ||
| 142 | if id(target) not in self.potion_effects: | 140 | if id(target) not in self.potion_effects: | ||
| 143 | self.potion_effects[id(target)] = [potion] | 141 | self.potion_effects[id(target)] = [potion] | ||
| 144 | else: | 142 | else: | ||
| 145 | self.potion_effects[id(target)].append(potion) | 143 | self.potion_effects[id(target)].append(potion) | ||
| 146 | 144 | ||||
| n | 147 | n | |||
| 148 | for effect in potion.effects: | 145 | for effect in potion.effects: | ||
| 149 | potion.effects[effect](target) | 146 | potion.effects[effect](target) | ||
| 150 | 147 | ||||
| 151 | potion.used = True | 148 | potion.used = True | ||
| 152 | 149 | ||||
| 153 | def tick(self) -> None: | 150 | def tick(self) -> None: | ||
| 154 | for target in self.affected_targets: | 151 | for target in self.affected_targets: | ||
| n | 155 | n | |||
| 156 | flag = False | 152 | flag = False | ||
| t | 157 | potion : Potion | t | ||
| 158 | for potion in self.potion_effects[id(target)]: | 153 | for potion in self.potion_effects[id(target)]: | ||
| 159 | if potion.duration > 0: | 154 | if potion.duration > 0: | ||
| 160 | potion.duration -= 1 | 155 | potion.duration -= 1 | ||
| 161 | else: | 156 | else: | ||
| 162 | flag = True | 157 | flag = True | ||
| 163 | if flag: | 158 | if flag: | ||
| 164 | self.potion_effects[id(target)] = [potion for potion in self.potion_effects[id(target)] if potion.duration > 0] | 159 | self.potion_effects[id(target)] = [potion for potion in self.potion_effects[id(target)] if potion.duration > 0] | ||
| 165 | temp_target = copy.deepcopy(self.original_targets[id(target)]) | 160 | temp_target = copy.deepcopy(self.original_targets[id(target)]) | ||
| 166 | for potion in self.potion_effects[id(target)]: | 161 | for potion in self.potion_effects[id(target)]: | ||
| 167 | potion.used = False | 162 | potion.used = False | ||
| 168 | self.apply(temp_target, potion) | 163 | self.apply(temp_target, potion) | ||
| 169 | target = temp_target | 164 | target = temp_target | ||
| 170 | 165 | ||||
| 171 | 166 | ||||
| 172 | 167 | ||||
| 173 | 168 | ||||
| 174 | """ | 169 | """ | ||
| 175 | 170 | ||||
| 176 | effects = {'grow': lambda target: setattr(target, 'size', target.size*2)} | 171 | effects = {'grow': lambda target: setattr(target, 'size', target.size*2)} | ||
| 177 | 172 | ||||
| 178 | class Target: | 173 | class Target: | ||
| 179 | 174 | ||||
| 180 | def __init__(self) -> None: | 175 | def __init__(self) -> None: | ||
| 181 | self.size = 5 | 176 | self.size = 5 | ||
| 182 | 177 | ||||
| 183 | class TestTarget: | 178 | class TestTarget: | ||
| 184 | def __init__(self, x , y, size) -> None: | 179 | def __init__(self, x , y, size) -> None: | ||
| 185 | self.x = x | 180 | self.x = x | ||
| 186 | self.y = y | 181 | self.y = y | ||
| 187 | self.size = size | 182 | self.size = size | ||
| 188 | 183 | ||||
| 189 | target = Target() | 184 | target = Target() | ||
| 190 | 185 | ||||
| 191 | grow = Potion(effects=effects, duration=3) | 186 | grow = Potion(effects=effects, duration=3) | ||
| 192 | print(target.size) | 187 | print(target.size) | ||
| 193 | narco = ГоспожатаПоХимия() | 188 | narco = ГоспожатаПоХимия() | ||
| 194 | narco.apply(target, grow) | 189 | narco.apply(target, grow) | ||
| 195 | 190 | ||||
| 196 | print(target.size) | 191 | print(target.size) | ||
| 197 | narco.tick() | 192 | narco.tick() | ||
| 198 | print(target.size) | 193 | print(target.size) | ||
| 199 | narco.tick() | 194 | narco.tick() | ||
| 200 | print(target.size) | 195 | print(target.size) | ||
| 201 | narco.tick() | 196 | narco.tick() | ||
| 202 | print(target.size) | 197 | print(target.size) | ||
| 203 | narco.tick() | 198 | narco.tick() | ||
| 204 | print(target.size) | 199 | print(target.size) | ||
| 205 | narco.tick() | 200 | narco.tick() | ||
| 206 | print(target.size) | 201 | print(target.size) | ||
| 207 | 202 | ||||
| 208 | 203 | ||||
| 209 | teleport_potion | 204 | teleport_potion | ||
| 210 | combined_potion = teleport_potion + grow_potion | 205 | combined_potion = teleport_potion + grow_potion | ||
| 211 | 206 | ||||
| 212 | target = TestTarget(1, 1, 1) | 207 | target = TestTarget(1, 1, 1) | ||
| 213 | 208 | ||||
| 214 | combined_potion.teleport(target) | 209 | combined_potion.teleport(target) | ||
| 215 | combined_potion.grow(target) | 210 | combined_potion.grow(target) | ||
| 216 | 211 | ||||
| 217 | """ | 212 | """ | ||
| 218 | 213 | ||||
| 219 | #target.size = 5 | 214 | #target.size = 5 | ||
| 220 | #grow = Potion(effects=effects, duration=2) * 3 | 215 | #grow = Potion(effects=effects, duration=2) * 3 | ||
| 221 | #grow.grow(target) | 216 | #grow.grow(target) | ||
| 222 | #print(target.size) | 217 | #print(target.size) | ||
| 223 | 218 | ||||
| 224 | #target.size = 5 | 219 | #target.size = 5 | ||
| 225 | #grow = Potion(effects=effects, duration=2) * 3 | 220 | #grow = Potion(effects=effects, duration=2) * 3 | ||
| 226 | #grow = grow * 0.33 | 221 | #grow = grow * 0.33 | ||
| 227 | #grow.grow(target) | 222 | #grow.grow(target) | ||
| 228 | #print(target.size) | 223 | #print(target.size) | ||
| 229 | 224 | ||||
| 230 | #target.size = 5 | 225 | #target.size = 5 | ||
| 231 | #grow = Potion(effects=effects, duration=2) * 3 | 226 | #grow = Potion(effects=effects, duration=2) * 3 | ||
| 232 | #grow = grow - Potion(effects=effects, duration=2) | 227 | #grow = grow - Potion(effects=effects, duration=2) | ||
| 233 | #grow = grow - Potion(effects=effects, duration=2) | 228 | #grow = grow - Potion(effects=effects, duration=2) | ||
| 234 | #grow = grow - Potion(effects=effects, duration=2) | 229 | #grow = grow - Potion(effects=effects, duration=2) | ||
| 235 | #grow.grow(target) | 230 | #grow.grow(target) | ||
| 236 | #print(target.size) | 231 | #print(target.size) | ||
| 237 | 232 | ||||
| 238 | 233 | ||||
| 239 | #grow = Potion(effects=effects, duration=2) | 234 | #grow = Potion(effects=effects, duration=2) | ||
| 240 | #grow.potency["grow"] = 4 | 235 | #grow.potency["grow"] = 4 | ||
| 241 | 236 | ||||
| 242 | #small_grow ,_= grow / 2 | 237 | #small_grow ,_= grow / 2 | ||
| 243 | #small_grow.grow(target) | 238 | #small_grow.grow(target) | ||
| 244 | #print(target.size) | 239 | #print(target.size) | ||
| 245 | 240 | ||||
| 246 | #grow = Potion(effects=effects, duration=2) | 241 | #grow = Potion(effects=effects, duration=2) | ||
| 247 | #grow2 = Potion(effects=effects, duration=2) | 242 | #grow2 = Potion(effects=effects, duration=2) | ||
| 248 | #grow2.potency["grow"] = 1 | 243 | #grow2.potency["grow"] = 1 | ||
| 249 | #print(grow == grow2) | 244 | #print(grow == grow2) | ||
| 250 | 245 | ||||
| 251 | 246 | ||||
| 252 | #d = { "d":3454, "22":3456, "agds":5345, "A":456, "X":4567, "CCCCCCCCCCCCCCCCCCC":56} | 247 | #d = { "d":3454, "22":3456, "agds":5345, "A":456, "X":4567, "CCCCCCCCCCCCCCCCCCC":56} | ||
| 253 | #d={k:d[k] for k in sorted(d,key=calculate_molecular_mass)} | 248 | #d={k:d[k] for k in sorted(d,key=calculate_molecular_mass)} | ||
| 254 | #print(d) | 249 | #print(d) | ||
| 255 | 250 | ||||
| 256 | #target = Target() | 251 | #target = Target() | ||
| 257 | #target2 = copy.copy(target) | 252 | #target2 = copy.copy(target) | ||
| 258 | #print(target.size, target2.size) | 253 | #print(target.size, target2.size) | ||
| 259 | #target2.size = 10 | 254 | #target2.size = 10 | ||
| 260 | #print(target.size, target2.size) | 255 | #print(target.size, target2.size) | ||
| 261 | 256 | ||||
| 262 | 257 | ||||
| 263 | 258 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||