Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Whatever floats your 50% solution in Clear category for The Vampires by veky
from dataclasses import dataclass
from collections import deque
@dataclass
class Warrior:
health: int = 50
attack: int = 5
defense: int = int()
vampirism: float = float()
@property
def is_alive(self): return self.health > 0
def hit(self, other):
if self.is_alive and (damage := self.attack - other.defense) > 0:
other.health -= damage
self.health += self.vampirism * damage
@dataclass
class Knight(Warrior):
attack: int = 7
@dataclass
class Defender(Warrior):
health: int = 60
attack: int = 3
defense: int = 2
@dataclass
class Vampire(Warrior):
health: int = 40
attack: int = 4
vampirism: float = 50 / 100
def fight(first, second):
while first.is_alive and second.is_alive:
first.hit(second)
second.hit(first)
return first.is_alive
class Army(deque):
def add_units(self, cls, n): self.extend(cls() for _ in range(n))
class Battle:
@staticmethod
def fight(*armies):
while True:
field = []
for i, army in enumerate(armies):
try: field.append(army[0])
except IndexError: return i
armies[fight(*field)].popleft()
Aug. 31, 2019
Comments: