Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. """
  2. This is an example for a bot.
  3. """
  4. from penguin_game import *
  5. from collections import *
  6. from operator import *
  7. from random import *
  8. from re import *
  9. from math import *
  10. from itertools import *
  11. from time import *
  12. from traceback import *
  13. from abc import *
  14.  
  15. def FurthestIceberg(game, my_iceberg):
  16. '''
  17. :param game:
  18. :param my_iceberg:
  19. :return:
  20. '''
  21. distance = 0
  22. further = 0
  23. for e_iceberg in game.get_enemy_icebergs():
  24. if my_iceberg.get_turns_till_arrival(e_iceberg) > distance:
  25. distance = my_iceberg.get_turns_till_arrival(e_iceberg)
  26. further = e_iceberg
  27.  
  28. return further
  29. def FewestPengstIceberg(game, my_iceberg):
  30. '''
  31. :param game:
  32. :param my_iceberg:
  33. :return:
  34. '''
  35. num = 0
  36. ice = 0
  37. for e_iceberg in game.get_enemy_icebergs():
  38. if my_iceberg.penguin_amount> num:
  39. num = my_iceberg.penguin_amount
  40. ice = e_iceberg
  41.  
  42. return ice
  43.  
  44. def alarm_on(game):
  45. return len(game.get_enemy_icebergs())> len(game.get_my_icebergs())+len(game.get_neutral_icebergs())
  46.  
  47. def do_turn(game):
  48. """
  49. Makes the bot run a single turn.
  50.  
  51. :param game: the current game state.
  52. :type game: Game
  53. """
  54.  
  55. if len(game.get_my_icebergs()) ==1 :
  56. destination = FurthestIceberg(game, game.get_my_icebergs()[0])
  57. game.get_my_icebergs()[0].send_penguins(destination,2) # destination.penguin_amount +
  58. elif alarm_on(game):
  59. print ("ALARM ON, I REPEAT, ALARM ON!")
  60.  
  61. else:
  62.  
  63. # Go over all of my icebergs.
  64. for my_iceberg in game.get_my_icebergs():
  65. # The amount of penguins in my iceberg.
  66. my_penguin_amount = my_iceberg.penguin_amount # type: int
  67.  
  68. # If there are any neutral icebergs.
  69. if game.get_neutral_icebergs():
  70. # Target a neutral iceberg.
  71. destination = game.get_neutral_icebergs()[0] # type: Iceberg
  72. else:
  73. # Target an enemy iceberg.
  74. destination = FewestPengstIceberg(game,my_penguin_amount) # type: Iceberg
  75.  
  76. # The amount of penguins the target has.
  77. destination_penguin_amount = destination.penguin_amount # type: int
  78.  
  79. # If my iceberg has more penguins than the target iceberg.
  80. if my_penguin_amount > destination_penguin_amount:
  81. # Send penguins to the target.
  82. print (my_iceberg, "sends", (destination_penguin_amount + 1), "penguins to", destination)
  83. my_iceberg.send_penguins(destination, destination_penguin_amount + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement