checkio-missions-set-war's People
Forkers
katerinasand rydia001 maartincm jiangyuebing destitutus akapawat allburov igharok checkio-missions pouf philippe-choletcheckio-missions-set-war's Issues
Fault in The Defenders mission
https://py.checkio.org/mission/the-defenders/
Old description without Rookie class and always error with this test.
Need only True or False by description but return 60
Thanks
"8. Fight": [
prepare_test(middle_code='''unit_1 = Defender()
unit_2 = Rookie()
fight(unit_1, unit_2)''',
test="unit_1.health",
answer=60)
],
Test for The Lancers is too simple
Looks like test is too simple for The Lancers task
Just adding a class of Lancer allow to pass all test
Probably is good to add a case then lancers are wins because of additional damage
battle = Battle()
army_1 = Army()
army_2 = Army()
army_1.add_units(Lancer, 2)
army_2.add_units(Warrior, 3)
assert battle.fight(army_1, army_2) == True
Rookie produce bug in some case
In "The Defenders" mission, a class Rookie(Warrior) is secretly added in judge, and they do not do super().init().
My code did not pass these test because my implementation assumes defense and is_alive are set as 0 and True as default at the init timing, respectively.
Please add super().init() in Rookie().init() as in my pull request.
Check fail Weapon 10 test
I have a problem with 10th weapon test in "The Weapons" mission. Can you plz help me with that?
My code, which I'll put on bottom, is passing all test in my ide. But somehow I got troubles with passing 10th test and also if i add that test manually on main function and click run on cleckio site it also passes.
Error I got: "IndexError: list index out of range, , 119"
code
`import math
class Warrior():
def __init__(self, attack=5, health=50, max_health=50, defense=0, vampirism=0.0, piercing=0., heal_power=0):
self.attack = attack
self.max_health = max_health
self.health = max_health
self.defense = defense
self.vampirism = vampirism
self.piercing = piercing
self.heal_power = heal_power
@property
def is_alive(self):
return self.health > 0
def heal(self, allie):
allie.health = allie.health + self.heal_power if allie.health + self.heal_power < allie.max_health else allie.max_health
return allie
def equip_weapon(self, weapon):
self.max_health = self.max_health + weapon.health if self.max_health + weapon.health > 0 else 0
self.health = self.health + weapon.health if self.health + self.health > 0 else 0
self.attack = self.attack + weapon.attack if self.attack + weapon.attack > 0 else 0
self.defense = self.defense + weapon.defense if self.defense and self.defense+weapon.defense > 0 else 0
self.vampirism = self.vampirism + weapon.vampirism if self.vampirism and self.vampirism + weapon.vampirism > 0. else 0.
self.heal_power = self.heal_power + weapon.heal_power if self.heal_power else 0
class Rookie(Warrior):
def __init__(self, attack=1, health=50, max_health=50, defense=0, vampirism=0., piercing=0., heal_power=0):
super().__init__(attack, health, max_health, defense, vampirism, piercing, heal_power)
class Knight(Warrior):
def __init__(self, attack=7, health=50, max_health=50, defense=0, vampirism=0., piercing=0., heal_power=0):
super().__init__(attack, health, max_health, defense, vampirism, piercing, heal_power)
class Defender(Warrior):
def __init__(self, attack=3, health=60, max_health=60, defense=2, vampirism=0., piercing=0., heal_power=0):
super().__init__(attack, health, max_health, defense, vampirism, piercing, heal_power)
class Vampire(Warrior):
def __init__(self, attack=4, health=40, max_health=40, defense=0, vampirism=0.5, piercing=0., heal_power=0):
super().__init__(attack, health, max_health, defense, vampirism, piercing, heal_power)
class Lancer(Warrior):
def __init__(self, attack=6, health=50, max_health=50, defense=0, vampirism=0., piercing=0.5, heal_power=0):
super().__init__(attack, health, max_health, defense, vampirism, piercing, heal_power)
class Healer(Warrior):
def __init__(self, attack=0, health=60, max_health=60, defense=0, vampirism=0., piercing=0, heal_power=2):
super().__init__(attack, health, max_health, defense, vampirism, piercing, heal_power)
class Weapon():
def __init__(self, health=0, attack=0, defense=0, vampirism=0.0, heal_power=0):
self.health = health
self.attack = attack
self.defense = defense
self.vampirism = vampirism
self.heal_power = heal_power
class Sword(Weapon):
def __init__(self, health=5, attack=2, defense=0, vampirism=0.0, heal_power=0):
super().__init__(health, attack, defense, vampirism, heal_power)
class Shield(Weapon):
def __init__(self, health=20, attack=0, defense=2, vampirism=0.0, heal_power=0):
super().__init__(health, attack, defense, vampirism, heal_power)
class GreatAxe(Weapon):
def __init__(self, health=-15, attack=5, defense=-2, vampirism=0.1, heal_power=0):
super().__init__(health, attack, defense, vampirism, heal_power)
class Katana(Weapon):
def __init__(self, health=-20, attack=6, defense=-5, vampirism=0.5, heal_power=0):
super().__init__(health, attack, defense, vampirism, heal_power)
class MagicWand(Weapon):
def __init__(self, health=30, attack=3, defense=0, vampirism=0.0, heal_power=3):
super().__init__(health, attack, defense, vampirism, heal_power)
class Army():
def __init__(self):
self.units = []
def add_units(self, warrior_type, count):
for c in range(count):
if warrior_type == Warrior:
self.units.append(Warrior())
if warrior_type == Knight:
self.units.append(Knight())
elif warrior_type == Defender:
self.units.append(Defender())
elif warrior_type == Vampire:
self.units.append(Vampire())
elif warrior_type == Lancer:
self.units.append(Lancer())
elif warrior_type == Healer:
self.units.append(Healer())
elif warrior_type == Rookie:
self.units.append(Rookie())
def __len__(self):
return len(self.units)
def fight(unit_1, unit_2, unit_behind_1=False, unit_behind_2=False):
while(unit_1.is_alive and unit_2.is_alive):
if unit_2.defense < unit_1.attack:
do_damage(unit_1, unit_2, unit_behind_1, unit_behind_2)
if unit_2.is_alive:
if unit_1.defense < unit_2.attack:
do_damage(unit_2, unit_1, unit_behind_2, unit_behind_1)
return unit_1.is_alive
def do_damage(unit_1, unit_2, unit_behind_1=False, unit_behind_2=False):
prev_2 = unit_2.health
unit_2.health -= unit_1.attack - unit_2.defense
if unit_2.health < 0:
unit_2.health = 0
unit_1.health += math.floor((prev_2 - unit_2.health)*unit_1.vampirism)
if unit_behind_2:
unit_behind_2.health -= math.floor((unit_1.attack-unit_2.defense)*unit_1.piercing)
if unit_behind_1:
unit_1 = unit_behind_1.heal(unit_1)
class Battle():
@staticmethod
def fight(army_1, army_2):
while len(army_1) > 0 and len(army_2) > 0:
behind_unit_1, behind_unit_2 = False, False
if len(army_1)>1:
behind_unit_1 = army_1.units[1]
if len(army_2)>1:
behind_unit_2 = army_2.units[1]
if fight(army_1.units[0], army_2.units[0], behind_unit_1, behind_unit_2):
army_2.units.pop(0)
else:
army_1.units.pop(0)
return True if len(army_1) > 0 else False
@staticmethod
def one_round_duels(army_1, army_2):
nums_to_delete_1 = []
nums_to_delete_2 = []
for num in range(max(len(army_1), len(army_2))):
if num < len(army_1) and num < len(army_2):
if fight(army_1.units[num], army_2.units[num]):
nums_to_delete_2.append(num)
else:
nums_to_delete_1.append(num)
for index in reversed(nums_to_delete_1):
del army_1.units[index]
for index in reversed(nums_to_delete_2):
del army_2.units[index]
return army_1, army_2
@staticmethod
def straight_fight(army_1, army_2):
while len(army_1) > 0 and len(army_2) > 0:
Battle().one_round_duels(army_1, army_2)
return True if len(army_1) > 0 else False
if name == "main":
weapon_1 = Katana()
weapon_2 = Shield()
my_army = Army()
my_army.add_units(Vampire, 2)
my_army.add_units(Rookie, 2)
enemy_army = Army()
enemy_army.add_units(Warrior, 1)
enemy_army.add_units(Defender, 2)
my_army.units[0].equip_weapon(weapon_1)
my_army.units[1].equip_weapon(weapon_1)
my_army.units[2].equip_weapon(weapon_2)
enemy_army.units[0].equip_weapon(weapon_1)
enemy_army.units[1].equip_weapon(weapon_2)
enemy_army.units[2].equip_weapon(weapon_2)
battle = Battle()
assert battle.straight_fight(my_army, enemy_army) == True`
Army Battles Issue at py.checkio
I finished my code and all test cases are passed but I noticed an error in one of the test case and its not letting me finish the challenge as I have to skip it in order to proceed.
The condition was : In this case, the battle() function should return True, if the first army won, or False, if the second one was stronger.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.