Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.00 KB | None | 0 0
  1. """
  2. This is an example for a bot.
  3. """
  4. from penguin_game import *
  5.  
  6.  
  7. def do_turn(game):
  8.     """
  9.    Makes the bot run a single turn.
  10.  
  11.    :param game: the current game state.
  12.    :type game: Game
  13.    """
  14.     # Go over all of my icebergs.
  15.     for my_iceberg in game.get_my_icebergs():
  16.          if my_iceberg.can_upgrade():
  17.              my_iceberg.upgrade()
  18.          else:
  19.              if iceberg_being_attacked_by_enemy(game):
  20.                  attacked = which_iceberg_being_attacked_by_enemy(game)
  21.                  if penguins_on_the_way(game, attacked) != True:
  22.                      iceberg_with_most_penguines(game).send_penguins(attacked, iceberg_with_most_penguines(game).penguin_amount / 2)
  23.              else:
  24.                  best_icebergs = list_of_best_icebergs(game, my_iceberg)
  25.                  if iceberg_being_attacked_by_me(best_icebergs[0]):
  26.                      try:
  27.                          my_iceberg.send_penguins(best_icebergs[1], calc_min_ping_conquere(game, my_iceberg, best_icebergs[1]) + 2)
  28.                      except: a = 0
  29.                  else:
  30.                      try:
  31.                          my_iceberg.send_penguins(best_icebergs[0], calc_min_ping_conquere(game, my_iceberg, best_icebergs[0]) + 2)
  32.                      except: a = 0
  33.  
  34.  
  35. def able_conquare(game, my_iceberg):
  36.      iceberg_able = []
  37.      for iceberg in game.get_neutral_icebergs() + game.get_enemy_icebergs():
  38.          if my_iceberg.penguin_amount >= calc_min_ping_conquere(game, my_iceberg, iceberg):
  39.              iceberg_able.append(iceberg)
  40.      return iceberg_able
  41.  
  42.  
  43. def calc_min_ping_conquere(game, my_iceberg, destination):
  44.      if destination in game.get_enemy_icebergs():
  45.          return destination.penguin_amount + my_iceberg.get_turns_till_arrival(destination) * destination.level + 1
  46.      return destination.penguin_amount + 1
  47.  
  48.  
  49. def list_of_best_icebergs(game, my_iceberg):
  50.      return sorted(able_conquare(game, my_iceberg), key=lambda iceberg: calc_min_ping_conquere(game, my_iceberg, iceberg))
  51.  
  52. """ """
  53. def iceberg_being_attacked_by_me(game, destination):
  54.      for groups in game.get_my_penguin_groups:
  55.          if groups.destination == destination:
  56.              return True
  57.      return False
  58.  
  59.  
  60. def iceberg_being_attacked_by_enemy(game):
  61.      for my_iceberg in game.get_my_icebergs():
  62.          for groups in game.get_enemy_penguin_groups():
  63.              if groups.destination == my_iceberg:
  64.                  return True
  65.      return False
  66.  
  67.  
  68. def which_iceberg_being_attacked_by_enemy(game):
  69.      for my_iceberg in game.get_my_icebergs():
  70.          for groups in game.get_enemy_penguin_groups():
  71.              if groups.destination == my_iceberg:
  72.                  return my_iceberg
  73.  
  74.  
  75. def iceberg_with_most_penguines(game):
  76.      return max (game.get_my_icebergs(), key = lambda ice: ice.penguin_amount )
  77.  
  78. def penguins_on_the_way(game, destination):
  79.      for groups in game.get_my_penguin_groups():
  80.          if groups.destination == destination:
  81.              return True
  82.      return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement