
Army Battles

Realizing that the forces are equal, each of them had followed the only course possible - to call for help. Umbert sent for the reinforcement his coachman on a horse, and Sir Ronald used a family horn that sounded more than once in hot battles. The knight's castle was close enough for the call to arms was heard back there. Nobody quite knew where the Umbert's accomplices were located, and this made it difficult to come up with a strategy for the battle ahead.
Fortunately, the reinforcements for both sides arrived almost simultaneously. Now it was more than a question of the girl's honor. There was no peaceful solutions to this matter. One of the two armies must be destroyed.
In the previous mission - Warriors - you've learned how to make a duel between 2 warriors happen. Great job! But let's move to something that feels a little more epic - the armies! In this mission your task is to add new classes and functions to the existing ones. The new class should be the Army and have the method add_units() - for adding the chosen amount of units to the army. The first unit added will be the first to go to fight, the second will be the second, ...
Also you need to create a Battle() class with a fight() function, which will determine the strongest army.
The battles occur according to the following principles:
at first, there is a duel between the first warrior of the first army and the first warrior of the second army (FIFO counting is used). As soon as one of them dies - the next warrior from the army that lost the fighter enters the duel, and the surviving warrior continues to fight with his current health. This continues until all the soldiers of one of the armies die. In this case, the fight() function should return True, if the first army won, or False, if the second one was stronger.
Note that army 1 have the advantage to start every fight!
Example:
chuck = Warrior() bruce = Warrior() carl = Knight() dave = Warrior() mark = Warrior() fight(chuck, bruce) == True fight(dave, carl) == False chuck.is_alive == True bruce.is_alive == False carl.is_alive == True dave.is_alive == False fight(carl, mark) == False carl.is_alive == False my_army = Army() my_army.add_units(Knight, 3) enemy_army = Army() enemy_army.add_units(Warrior, 3) army_3 = Army() army_3.add_units(Warrior, 20) army_3.add_units(Knight, 5) army_4 = Army() army_4.add_units(Warrior, 30) battle = Battle() battle.fight(my_army, enemy_army) == True battle.fight(army_3, army_4) == False
Input: The warriors and armies.
Output: The result of the battle (True or False).
How it is used: For computer games development.
Precondition:
- 2 types of units
- For all battles, each army is obviously not empty at the beginning.
CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.
In order to install CheckiO client you'll need installed Python (version at least 3.8)
Install CheckiO Client first:
pip3 install checkio_client
Configure your tool
checkio --domain=py config --key=
Sync solutions into your local folder
checkio sync
(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)
checkio serv -d
Alternatevly, you can install Chrome extension or FF addon
checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium
Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.