Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 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.     penguins_sent_to = []
  9.     """
  10.    Makes the bot run a single turn.
  11.  
  12.    :param game: the current game state.
  13.    :type game: Game
  14.    """
  15.     # Go over all of my icebergs.
  16.     for my_iceberg in game.get_my_icebergs():
  17.         # The amount of penguins in my iceberg.
  18.         my_penguin_amount = my_iceberg.penguin_amount  # type: int
  19.  
  20.         # If there are any neutral icebergs.
  21.         if game.get_neutral_icebergs():
  22.             if not my_iceberg in penguins_sent_to:
  23.             # Target a neutral iceberg.
  24.                 destination = game.get_neutral_icebergs()[0]  # type: Iceberg
  25.         else:
  26.             # Target a neutral iceberg.
  27.             destination = game.get_eneemy_icebergs()[0]  # type: Iceberg
  28.             # Target an enemy iceberg.
  29.            
  30.  
  31.         # The amount of penguins the target has.
  32.         destination_penguin_amount = destination.penguin_amount  # type: int
  33.         if my_iceberg.can_upgrade():
  34.             my_iceberg.upgrade()
  35.         # If my iceberg has more penguins than the target iceberg.
  36.         elif my_penguin_amount > destination_penguin_amount:
  37.             # Send penguins to the target.
  38.             print my_iceberg, "sends", (destination_penguin_amount + 1), "penguins to", destination
  39.             my_iceberg.send_penguins(destination, destination_penguin_amount + 1)
  40.             penguins_sent_to.append(game.get_my_icebergs.index(my_iceberg))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement