remove runtimewarnings

This commit is contained in:
2024-04-20 15:10:02 +02:00
parent 89ee1df587
commit 25c48a9431
+13 -11
View File
@@ -69,23 +69,25 @@ class Player(Serializable):
async def _rebuild_stack(self):
"""Call when the player wants to draw but has no cards in stack_pile"""
if len(self.stack_pile) != 0:
raise RuntimeWarning("Cannot rebuild stack if stack is not empty!")
print("Cannot rebuild stack if stack is not empty!")
return
self.stack_pile, self.discard_pile = self.discard_pile, self.stack_pile
random.shuffle(self.stack_pile)
async def draw(self, amount: int):
"""Draw a card from the stack. Handles stack rebuild from discard automatically"""
try:
while amount > 0:
if len(self.stack_pile) == 0:
if len(self.discard_pile) == 0:
raise RuntimeWarning("No more cards to draw !")
await self._rebuild_stack()
if len(self.stack_pile) > 0:
self.hand.append(self.stack_pile.pop())
amount = amount - 1
finally:
while amount > 0:
if len(self.stack_pile) == 0:
if len(self.discard_pile) == 0:
print("No more cards to draw !")
break
await self._rebuild_stack()
if len(self.stack_pile) > 0:
self.hand.append(self.stack_pile.pop())
amount = amount - 1
await self.notify_update()
async def notify_update(self):