def test_1(battlefield): energy_source_1 = bot_game.EnergySource((1, 1), 10) energy_source_2 = bot_game.EnergySource((2, 3), 10) energy_source_3 = bot_game.EnergySource((4, 2), 10) energy_source_4 = bot_game.EnergySource((1, 4), 10) energy_source_5 = bot_game.EnergySource((3, 5), 10) battlefield.add_item(energy_source_1) battlefield.add_item(energy_source_2) battlefield.add_item(energy_source_3) battlefield.add_item(energy_source_4) battlefield.add_item(energy_source_5) ctlr_1 = controllers.SeekEnergyController() bot_1 = bot_game.Bot(coords=(0, 0), max_hp=10, hp=10, power=10, attack_range=1, speed=0, sight=10, energy=0, movement=1, player='1', message='', controller=ctlr_1) battlefield.add_item(bot_1)
def make_random_energy_sources(battlefield, amounts=None, num=20, border=5): width, height = battlefield.width, battlefield.height if amounts == None: amounts = [3, 5, 10, 10] for _ in range(num): x = random.randint(border, width - 1 - border) y = random.randint(border, height - 1 - border) m = random.randint(1, len(amounts)) sub_amounts = amounts[:m][::-1] # print(len(sub_amounts)) # print('center: {}'.format((x, y))) for i, amount in enumerate(sub_amounts): # print('{}, {}'.format(amount, i)) coords_to_fill = bot_game.coords_at_distance((x, y), i) coords_to_fill = [c for c in coords_to_fill\ if battlefield.is_in_bounds(c)] for c in coords_to_fill: # print(c) es_there = battlefield.of_type_at(c, bot_game.EnergySource) if es_there: total_amount = amount + es_there[0].amount battlefield.remove_item(es_there[0]) new_es = bot_game.EnergySource(c, total_amount) battlefield.add_item(new_es) else: es = bot_game.EnergySource(c, amount) battlefield.add_item(es)
def get_start_energy_sources(amount=5, battlefield=None, width=None, height=None): if battlefield: width = width if width else battlefield.width height = height if height else battlefield.height es_1 = bot_game.EnergySource((0, 0), amount) es_2 = bot_game.EnergySource((width - 1, height - 1), amount) return es_1, es_2
def heal_test_1(battlefield): energy_source = bot_game.EnergySource((0, 0), 10) battlefield.add_item(energy_source) heal_controller = controllers.GiveLifeController() heal_bot = bot_game.Bot(coords=(0, 0), max_hp=100, hp=10, power=10, attack_range=1, speed=0, sight=5, energy=0, movement=1, player='1', message='RIGHT', controller=heal_controller, heal=1) battlefield.add_item(heal_bot)
def give_energy_test_1(battlefield): """ Test GIVE_ENERGY processing. """ energy_source = bot_game.EnergySource((0, 0), 10) battlefield.add_item(energy_source) controller = controllers.ChainEnergyController() bot = bot_game.Bot(coords=(0, 0), max_hp=10, hp=10, power=10, attack_range=1, speed=0, sight=5, energy=0, movement=1, player='1', message='RIGHT', special_stats=dict(), controller=controller) battlefield.add_item(bot)
def give_life_test_1(battlefield): energy_source = bot_game.EnergySource((0, 0), 10) battlefield.add_item(energy_source) heal_controller = controllers.GiveLifeController() heal_bot = bot_game.Bot(coords=(0, 0), max_hp=100, hp=10, power=10, attack_range=1, speed=0, sight=5, energy=0, movement=1, player='1', message='RIGHT', controller=heal_controller, heal=1) battlefield.add_item(heal_bot) print('heal_bot.heal: {}'.format(heal_bot.heal)) sit_controller = controllers.SitController() hurt_bot = bot_game.Bot(coords=(1, 0), max_hp=100, hp=10, power=10, attack_range=1, speed=0, sight=5, energy=0, movement=1, player='1', message='RIGHT', special_stats=dict(), controller=sit_controller) battlefield.add_item(hurt_bot)