Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. """
  2. This is an example for a bot.
  3. """
  4. from pirates 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: PirateGame
  13. """
  14.  
  15.  
  16.  
  17. PIRATE4 = game.get_all_my_pirates()[0]
  18. PIRATE5 = game.get_all_my_pirates()[1]
  19. PIRATE6 = game.get_all_my_pirates()[2]
  20. DEFENCE_PUSH = game.get_enemy_mothership()
  21. # Get one of my pirates.
  22.  
  23.  
  24. move_to_defence(game, PIRATE4, PIRATE5, DEFENCE_PUSH, PIRATE6)
  25.  
  26. capsule_spawn = game.get_my_capsule().initial_location
  27. for x in game.get_all_my_pirates():
  28. print(x)
  29. attack_route(game, capsule_spawn, game.get_my_capsule().holder)
  30.  
  31. """
  32. # Try to push, if you didn't - take the capsule and go to the mothership.
  33. if not try_push(pirate, game):
  34. # If the pirate doesn't have a capsule, go and get it!
  35. if pirate.capsule is None:
  36. capsule = game.get_my_capsule()
  37. pirate.sail(capsule)
  38. # Else, go to my mothership.
  39. else:
  40. mothership = game.get_my_mothership()
  41. # Go towards the mothership.
  42. pirate.sail(mothership)
  43.  
  44. """
  45. capsule_spawn = game.get_my_capsule().get_location()
  46.  
  47.  
  48.  
  49.  
  50.  
  51. def try_push(pirate, game):
  52. """
  53. Makes the pirate try to push an enemy pirate. Returns True if it did.
  54.  
  55. :param pirate: The pushing pirate.
  56. :type pirate: Pirate
  57. :param game: The current game state.
  58. :type game: PirateGame
  59. :return: True if the pirate pushed.
  60. :rtype: bool
  61. """
  62. # Go over all enemies.
  63. for enemy in game.get_enemy_living_pirates():
  64. # Check if the pirate can push the enemy.
  65. if pirate.can_push(enemy):
  66. # Push enemy!
  67. pirate.push(enemy, enemy.initial_location)
  68. # Print a message.
  69. print 'pirate', pirate, 'pushes', enemy, 'towards', enemy.initial_location
  70. # Did push.
  71. return True
  72.  
  73. # Didn't push.
  74. return False
  75.  
  76. def move_to_defence(game, PIRATE0, PIRATE1, DEFENCE_PUSH, PIRATE2):
  77.  
  78. location_to_go = Location(3486,5305)
  79. DEFENCE_PUSH = Location(3486,6511)
  80.  
  81. for pirate_temp in [PIRATE0, PIRATE1, PIRATE2]:
  82. if not pirate_temp.get_location().equals(location_to_go):
  83. pirate_temp.sail(location_to_go)
  84. else:
  85. ctr_push = 0
  86. for pirate_temp in [PIRATE0, PIRATE1, PIRATE2]:
  87. if pirate_temp.can_push(game.get_enemy_capsule()) :
  88. ctr_push = ctr_push + 1
  89. #if ctr_push > 1:
  90. pirate_temp.push(game.get_enemy_capsule().holder, DEFENCE_PUSH)
  91.  
  92.  
  93.  
  94. def checkBorders(pirate, game):
  95. """
  96. checks if the ship is on a danger of crashing (600 instead of 900 )
  97. """
  98. print ("inside checkBorders")
  99. danger = 600 < pirate.location().col < 5800 and 600 < pirate.location().row < 5800
  100. if(danger):
  101. print("Our ship is in danger.")
  102. return (danger)
  103.  
  104.  
  105. def attack_route(game, capsule_spawn, holder):
  106. mothership = game.get_my_mothership()
  107. capsule = game.get_my_capsule()
  108. lst = game.get_all_my_pirates()
  109.  
  110. for x in lst:
  111. pushed = False
  112. if x.turns_to_revive != 0:
  113. continue
  114. for en in game.get_enemy_living_pirates():
  115. if x.can_push(en):
  116. x.push(en, game.get_enemy_mothership())
  117. pushed = True
  118. break
  119. if not pushed:
  120. if(x.equals(lst[0]) or x.equals(lst[1]) or x.equals(lst[2])):
  121. continue
  122. else:
  123. for a in lst:
  124. if (x.in_push_range(a)):
  125. y = lst.index(a)
  126. break
  127. LastLocation = Location(a.get_location().row, a.get_location().col)
  128. #if(x.has_capsule()):
  129. # x.max_speed = 10
  130. #else:
  131. # x.max_sp#eed = 200
  132. if(x.has_capsule() and (x.distance(mothership)+100 <= lst[y].distance(mothership))):
  133. x.sail(LastLocation)
  134. if(holder == None):
  135. x.sail(capsule)
  136. else:
  137. x.sail(mothership)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement