Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple using indices to alternate solution in Clear category for The Warriors by cheikhnamouna
from itertools import cycle
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
@property
def is_alive(self):
return self.health > 0
class Knight(Warrior):
def __init__(self):
super().__init__()
self.attack = 7
def fight(u1, u2):
fighters, i = [u1, u2], 0
while u1.is_alive and u2.is_alive:
attacker, attacked, i = fighters[i], fighters[1 - i], 1 - i
attacked.health -= attacker.attack
return u1.is_alive
Dec. 30, 2018