Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1. """
  2. This is an example for a bot.
  3. """
  4. from penguin_game import *
  5.  
  6. def check_if_sent(Game(game), int(id):
  7.     for pg in game.get_my_penguin_groups():
  8.         if pg.destination.id == id:
  9.             print "sent groups to this enemy"
  10.             return False
  11.    
  12. situation = 1
  13.  
  14.  
  15. def do_turn(game):
  16.     penguins_sent = []
  17.     ze_penguin = 0
  18.     low = 10000
  19.    
  20.     """
  21.    Makes the bot run a single turn.
  22.  
  23.    :param game: the current game state.
  24.    :type game: Game
  25.    """
  26.     # Go over all of my icebergs.
  27.     for my_iceberg in game.get_my_icebergs():
  28.         # The amount of penguins in my iceberg.
  29.         my_penguin_amount = my_iceberg.penguin_amount  # type: int
  30.  
  31.         # If there are any neutral icebergs.
  32.         if game.get_neutral_icebergs():
  33.             # Target a neutral iceberg.
  34.             for berg in game.get_neutral_icebergs():
  35.                 if berg.penguin_amount < low:
  36.                     low = berg.penguin_amount
  37.                     ze_penguin = game.get_neutral_icebergs().index(berg)
  38.                    
  39.                
  40.             destination = game.get_neutral_icebergs()[ze_penguin]  # type: Iceberg
  41.             situation = 1
  42.         else:
  43.             # Target an enemy iceberg.
  44.             for berg in game.get_enemy_icebergs():
  45.                 if berg.penguin_amount < low:
  46.                     low = berg.penguin_amount
  47.                     ze_penguin = game.get_enemy_icebergs().index(berg)
  48.             destination = game.get_enemy_icebergs()[0]  # type: Iceberg
  49.             situation = 2
  50.  
  51.         # The amount of penguins the target has.
  52.         destination_penguin_amount = destination.penguin_amount  # type: int
  53.         if my_iceberg.can_upgrade():
  54.             my_iceberg.upgrade()
  55.         # If my iceberg has more penguins than the target iceberg.
  56.         elif my_penguin_amount > destination_penguin_amount:
  57.             if (situation == 1):
  58.                 if check_if_sent(game.get_neutral_icebergs().index[destination]):
  59.                 # Send penguins to the target.
  60.                     print my_iceberg, "sends", (destination_penguin_amount + 1), "penguins to", destination
  61.                     my_iceberg.send_penguins(destination, destination_penguin_amount + 1)
  62.             elif(situation = 2):
  63.                  if check_if_sent(game.get_enemy_icebergs().index[destination]):
  64.                 # Send penguins to the target.
  65.                     print my_iceberg, "sends", (destination_penguin_amount + 1), "penguins to", destination
  66.                     my_iceberg.send_penguins(destination, destination_penguin_amount + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement