Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for The Vampires by fed.kz
class Warrior:
def __init__(self):
self.health=50
self.attack=5
self.defense=0
@property
def is_alive(self):
return self.health>0
class Knight(Warrior):
def __init__(self):
self.health=50
self.attack=7
class Defender(Warrior):
def __init__(self):
self.health=60
self.attack=3
self.defense=2
class Vampire(Warrior):
def __init__(self):
self.health=40
self.attack=4
self.vampirism=0.5
def fight(first,second):
for warrior in (first,second):
for attribute in ('defense','vampirism'):
if not hasattr(warrior,attribute):
setattr(warrior,attribute,0)
while first.is_alive and second.is_alive:
second.health=min(second.health,second.health-(first.attack-second.defense))
first.health+=max(first.attack-second.defense,0)*first.vampirism
if second.health>0:
first.health=min(first.health-(second.attack-first.defense),first.health)
second.health+=max(second.attack-first.defense,0)*second.vampirism
else: return True
return False
class Army:
def __init__(self):
self.army=[]
def add_units(self,__class__,count):
while count:
self.army+=[__class__()]
count-=1
class Battle(Army):
def __init__(self):
super().__init__()
def fight(self,army1,army2):
while army1.army and army2.army:
war1=army1.army[0]
war2=army2.army[0]
if fight(war1,war2):
army2.army=army2.army[1:]
else: army1.army=army1.army[1:]
return army1.army!=[]
Aug. 9, 2018
Comments: