Esempio n. 1
0
def test_simple_movement():
    input_map = '''#######
#.E...#
#.....#
#...G.#
#######'''
    after_map = '''#######
#..E..#
#.....#
#...G.#
#######'''
    fight = day15.Fight(input_map)
    unit = fight.move_list()[0]
    unit.move_in(fight)
    fight_after = day15.Fight(after_map)
    assert fight == fight_after
Esempio n. 2
0
def test_find_tgt():
    input_map = '''#######
#E..G.#
#...#.#
#.G.#G#
#######'''
    fight = day15.Fight(input_map)
    unit = fight.move_list()[0]
    tgt = unit.find_target(fight, unit.distance_map(fight.map))
    assert np.array_equal(tgt.position, np.array([3, 1]))
Esempio n. 3
0
def test_outcome1():
    maps = combat_step_maps.split('\n\n')
    initial_state, *final_states = maps
    initial_state_match = re.match(r'(Initially:\n)(.*)', initial_state,
                                   re.DOTALL)
    initial_state = initial_state_match.group(2)
    initial_state, initial_hp_list = extract_hp_list(initial_state)
    assert all([item[1] == 200 for item in initial_hp_list])
    fight = day15.Fight(initial_state)
    fight.evolve()
    assert fight.outcome() == 27730
Esempio n. 4
0
def test_reachable_tgts():
    input_map = '''#######
#E..G.#
#...#.#
#.G.#G#
#######'''
    fight = day15.Fight(input_map)
    unit = fight.move_list()[0]
    tgts = unit.get_all_targets(fight, unit.distance_map(fight.map))
    tgts = unit.filter_by_reachable(fight.map, tgts)
    tgts = [s.position for s in tgts]
    assert np.array_equal(tgts, np.array([[3, 1], [2, 2], [1, 3], [3, 3]]))
Esempio n. 5
0
def test_in_range():
    input_map = '''#######
#.G.E.#
#E.G.E#
#.G.EE#
#######'''
    fight = day15.Fight(input_map)
    move_list = fight.move_list()
    ir1 = [s.position for s in move_list[0].in_range_squares(fight.map)]
    ir2 = [s.position for s in move_list[-2].in_range_squares(fight.map)]
    assert np.array_equal(ir1, np.array([[1, 1], [3, 1], [2, 2]]))
    assert len(move_list[-1].in_range_squares(fight.map)) == 0
    assert np.array_equal(ir2, np.array([[4, 2], [3, 3]]))
Esempio n. 6
0
def check_evolution(initial_map,
                    final_map,
                    n_rounds,
                    hp_list=None,
                    ignore_hp=False,
                    outcome=None,
                    allow_elf_death=True,
                    expected_elf_power=None):
    fight = day15.Fight(initial_map, allow_elf_death=allow_elf_death)
    fight.evolve(n_rounds)
    after_fight = day15.Fight(final_map)
    if hp_list:
        for unit, hp_info in zip(after_fight.move_list(), hp_list):
            assert unit.type.to_string() == hp_info[0]
            unit.hit_points = hp_info[1]
    if ignore_hp:
        for a, b in zip(fight.move_list(), after_fight.move_list()):
            b.hit_points = a.hit_points
    assert fight == after_fight
    if outcome:
        assert fight.outcome() == outcome
    if expected_elf_power:
        assert fight.elf_attack_power == expected_elf_power
Esempio n. 7
0
def test_move_order():
    input_map = '''#######
#.G.E.#
#E.G.E#
#.G.E.#
#######'''
    positions = [
        np.array([2, 1]),
        np.array([4, 1]),
        np.array([1, 2]),
        np.array([3, 2]),
        np.array([5, 2]),
        np.array([2, 3]),
        np.array([4, 3]),
    ]
    fight = day15.Fight(input_map)
    nove_list = fight.move_list()
    assert all([
        np.array_equal(unit.position, pos)
        for unit, pos in zip(nove_list, positions)
    ])