This commit is contained in:
bridge
2025-10-04 14:57:11 +08:00
parent f933eea8ac
commit 25b018e10a
6 changed files with 112 additions and 62 deletions

View File

@@ -11,9 +11,11 @@ class MagicStone(int):
self.value = value
def exchange(self) -> tuple[int, int, int]:
_value, _upper = divmod(self.value, 100)
_value, _middle = divmod(_value, 100)
return _upper, _middle, _value
# 期望顺序:返回 (上品, 中品, 下品)
# 汇率100 下品 = 1 中品100 中品 = 1 上品
_middle_total, _lower = divmod(self.value, 100)
_upper, _middle = divmod(_middle_total, 100)
return _upper, _middle, _lower
def __str__(self) -> str:
_upper, _middle, _value = self.exchange()
@@ -24,7 +26,21 @@ class MagicStone(int):
return MagicStone(self.value + other)
return MagicStone(self.value + other.value)
def __iadd__(self, other: Union['MagicStone', int]) -> 'MagicStone':
if isinstance(other, int):
self.value += other
else:
self.value += other.value
return self
def __sub__(self, other: Union['MagicStone', int]) -> 'MagicStone':
if isinstance(other, int):
return MagicStone(self.value - other)
return MagicStone(self.value - other.value)
return MagicStone(self.value - other.value)
def __isub__(self, other: Union['MagicStone', int]) -> 'MagicStone':
if isinstance(other, int):
self.value -= other
else:
self.value -= other.value
return self