Пример #1
0
def main():
    battalion_processor = BattalionProcessor(2,
                                             horses=1,
                                             elephants=2,
                                             armoured_tanks=3,
                                             sling_guns=4)
    battalion_processor.add_battalion_substituation(BattalionType.ELEPHANTS,
                                                    BattalionType.HORSES, 2)
    battalion_processor.add_battalion_substituation(
        BattalionType.ARMOUREDTANKS, BattalionType.ELEPHANTS, 2)
    battalion_processor.add_battalion_substituation(
        BattalionType.SLINGGUNS, BattalionType.ARMOUREDTANKS, 2)
    lengaburu_army = Army(horses=100,
                          elephants=50,
                          armoured_tanks=10,
                          sling_guns=5)

    with open("input.txt", "r") as testcases:
        for testcase in testcases:
            input = [int(x.strip()) for x in testcase.split(",")]
            enemy_army = Army(horses=input[0],
                              elephants=input[1],
                              armoured_tanks=input[2],
                              sling_guns=input[3])
            planner = BattlePlanner(battalion_processor,
                                    deepcopy(lengaburu_army))
            result, army = planner.get_winning_army(enemy_army)
            display_result(input, result, army)
Пример #2
0
 def test_resolve_with_similar_battalion(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(horses=horses, elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     planner = BattlePlanner(bp, army)
     assert planner.resolve_with_similar_battalion(BattalionType.HORSES, 50) == 0
     assert planner.resolve_with_similar_battalion(BattalionType.ELEPHANTS, 80) == 30
     assert planner.resolve_with_similar_battalion(BattalionType.ARMOUREDTANKS, 20) == 10
Пример #3
0
 def test_resolve_battalion_3(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     our_army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(3, horses=horses, elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     bp.add_battalion_substituation(BattalionType.ELEPHANTS, BattalionType.HORSES, 2)                                
     bp.add_battalion_substituation(BattalionType.ARMOUREDTANKS, BattalionType.HORSES, 4)
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 30) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 104) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 105) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 106) == False
Пример #4
0
    def test_get_winning_army_3(self):
        horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
        our_army = Army(horses=horses, elephants=elephants,
                    armoured_tanks=armoured_tanks, sling_guns=sling_guns)
        enemy_army = Army(horses=600, elephants=100)
        horses_order, elephants_order, armoured_tanks_order, sling_guns_order = 1, 2, 3, 4
        bp = BattalionProcessor(4, horses=horses_order, elephants=elephants_order,
                                armoured_tanks=armoured_tanks_order,
                                sling_guns=sling_guns_order)
        bp.add_battalion_substituation(BattalionType.ELEPHANTS, BattalionType.HORSES, 1)                        

        battle_result, winning_army = BattlePlanner(bp, deepcopy(our_army)).get_winning_army(deepcopy(enemy_army))
        assert battle_result == False
        assert winning_army == {BattalionType.HORSES: 100,
                                BattalionType.ELEPHANTS: 50}
Пример #5
0
 def test_get_winning_army_1(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     our_army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     enemy_army = Army(horses=200, elephants=100,
                 armoured_tanks=20, sling_guns=10)
     horses_order, elephants_order, armoured_tanks_order, sling_guns_order = 1, 2, 3, 4
     bp = BattalionProcessor(2, horses=horses_order, elephants=elephants_order,
                             armoured_tanks=armoured_tanks_order,
                             sling_guns=sling_guns_order)
                             
     battle_result, winning_army = BattlePlanner(bp, deepcopy(our_army)).get_winning_army(deepcopy(enemy_army))
     assert battle_result == True
     assert winning_army == {BattalionType.HORSES: 100,
                             BattalionType.ELEPHANTS: 50,
                             BattalionType.ARMOUREDTANKS: 10,
                             BattalionType.SLINGGUNS: 5}
Пример #6
0
 def test_resolve_battalion_1(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     our_army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(1, horses=horses, elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     bp.add_battalion_substituation(BattalionType.ELEPHANTS, BattalionType.HORSES, 2)                                
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 199) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 200) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 201) == False
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 150) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 100) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 5) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 250) == False
Пример #7
0
 def test_resolve_battalion_4(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     our_army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(3, horses=horses, elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 29) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 30) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 31) == False
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 104) == False
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 105) == False
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 106) == False        
Пример #8
0
 def test_apply_power_rule(self):
     bp = BattlePlanner(BattalionProcessor(), Army())
     assert bp.apply_power_rule(7) == 4
     assert bp.apply_power_rule(5) == 3