Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This is an example for a bot.
- """
- from penguin_game import *
- def do_turn(game):
- """
- Makes the bot run a single turn.
- :param game: the current game state.
- :type game: Game
- """
- # Go over all of my icebergs.
- for my_iceberg in game.get_my_icebergs():
- if my_iceberg.can_upgrade():
- my_iceberg.upgrade()
- else:
- if iceberg_being_attacked_by_enemy(game):
- attacked = which_iceberg_being_attacked_by_enemy(game)
- if penguins_on_the_way(game, attacked) != True:
- iceberg_with_most_penguines(game).send_penguins(attacked, iceberg_with_most_penguines(game).penguin_amount / 2)
- else:
- best_icebergs = list_of_best_icebergs(game, my_iceberg)
- if iceberg_being_attacked_by_me(best_icebergs[0]):
- try:
- my_iceberg.send_penguins(best_icebergs[1], calc_min_ping_conquere(game, my_iceberg, best_icebergs[1]) + 2)
- except: a = 0
- else:
- try:
- my_iceberg.send_penguins(best_icebergs[0], calc_min_ping_conquere(game, my_iceberg, best_icebergs[0]) + 2)
- except: a = 0
- def able_conquare(game, my_iceberg):
- iceberg_able = []
- for iceberg in game.get_neutral_icebergs() + game.get_enemy_icebergs():
- if my_iceberg.penguin_amount >= calc_min_ping_conquere(game, my_iceberg, iceberg):
- iceberg_able.append(iceberg)
- return iceberg_able
- def calc_min_ping_conquere(game, my_iceberg, destination):
- if destination in game.get_enemy_icebergs():
- return destination.penguin_amount + my_iceberg.get_turns_till_arrival(destination) * destination.level + 1
- return destination.penguin_amount + 1
- def list_of_best_icebergs(game, my_iceberg):
- return sorted(able_conquare(game, my_iceberg), key=lambda iceberg: calc_min_ping_conquere(game, my_iceberg, iceberg))
- """ """
- def iceberg_being_attacked_by_me(game, destination):
- for groups in game.get_my_penguin_groups:
- if groups.destination == destination:
- return True
- return False
- def iceberg_being_attacked_by_enemy(game):
- for my_iceberg in game.get_my_icebergs():
- for groups in game.get_enemy_penguin_groups():
- if groups.destination == my_iceberg:
- return True
- return False
- def which_iceberg_being_attacked_by_enemy(game):
- for my_iceberg in game.get_my_icebergs():
- for groups in game.get_enemy_penguin_groups():
- if groups.destination == my_iceberg:
- return my_iceberg
- def iceberg_with_most_penguines(game):
- return max (game.get_my_icebergs(), key = lambda ice: ice.penguin_amount )
- def penguins_on_the_way(game, destination):
- for groups in game.get_my_penguin_groups():
- if groups.destination == destination:
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement