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 *
- from collections import *
- from operator import *
- from random import *
- from re import *
- from math import *
- from itertools import *
- from time import *
- from traceback import *
- from abc import *
- def FurthestIceberg(game, my_iceberg):
- '''
- :param game:
- :param my_iceberg:
- :return:
- '''
- distance = 0
- further = 0
- for e_iceberg in game.get_enemy_icebergs():
- if my_iceberg.get_turns_till_arrival(e_iceberg) > distance:
- distance = my_iceberg.get_turns_till_arrival(e_iceberg)
- further = e_iceberg
- return further
- def FewestPengstIceberg(game, my_iceberg):
- '''
- :param game:
- :param my_iceberg:
- :return:
- '''
- num = 0
- ice = 0
- for e_iceberg in game.get_enemy_icebergs():
- if my_iceberg.penguin_amount> num:
- num = my_iceberg.penguin_amount
- ice = e_iceberg
- return ice
- def alarm_on(game):
- return len(game.get_enemy_icebergs())> len(game.get_my_icebergs())+len(game.get_neutral_icebergs())
- def do_turn(game):
- """
- Makes the bot run a single turn.
- :param game: the current game state.
- :type game: Game
- """
- if len(game.get_my_icebergs()) ==1 :
- destination = FurthestIceberg(game, game.get_my_icebergs()[0])
- game.get_my_icebergs()[0].send_penguins(destination,2) # destination.penguin_amount +
- elif alarm_on(game):
- print ("ALARM ON, I REPEAT, ALARM ON!")
- else:
- # Go over all of my icebergs.
- for my_iceberg in game.get_my_icebergs():
- # The amount of penguins in my iceberg.
- my_penguin_amount = my_iceberg.penguin_amount # type: int
- # If there are any neutral icebergs.
- if game.get_neutral_icebergs():
- # Target a neutral iceberg.
- destination = game.get_neutral_icebergs()[0] # type: Iceberg
- else:
- # Target an enemy iceberg.
- destination = FewestPengstIceberg(game,my_penguin_amount) # type: Iceberg
- # The amount of penguins the target has.
- destination_penguin_amount = destination.penguin_amount # type: int
- # If my iceberg has more penguins than the target iceberg.
- if my_penguin_amount > destination_penguin_amount:
- # Send penguins to the target.
- print (my_iceberg, "sends", (destination_penguin_amount + 1), "penguins to", destination)
- my_iceberg.send_penguins(destination, destination_penguin_amount + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement