Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This is an example for a bot.
- """
- from pirates import *
- def do_turn(game):
- """
- Makes the bot run a single turn.
- :param game: The current game state.
- :type game: PirateGame
- """
- PIRATE4 = game.get_all_my_pirates()[0]
- PIRATE5 = game.get_all_my_pirates()[1]
- PIRATE6 = game.get_all_my_pirates()[2]
- DEFENCE_PUSH = game.get_enemy_mothership()
- # Get one of my pirates.
- move_to_defence(game, PIRATE4, PIRATE5, DEFENCE_PUSH, PIRATE6)
- capsule_spawn = game.get_my_capsule().initial_location
- for x in game.get_all_my_pirates():
- print(x)
- attack_route(game, capsule_spawn, game.get_my_capsule().holder)
- """
- # Try to push, if you didn't - take the capsule and go to the mothership.
- if not try_push(pirate, game):
- # If the pirate doesn't have a capsule, go and get it!
- if pirate.capsule is None:
- capsule = game.get_my_capsule()
- pirate.sail(capsule)
- # Else, go to my mothership.
- else:
- mothership = game.get_my_mothership()
- # Go towards the mothership.
- pirate.sail(mothership)
- """
- capsule_spawn = game.get_my_capsule().get_location()
- def try_push(pirate, game):
- """
- Makes the pirate try to push an enemy pirate. Returns True if it did.
- :param pirate: The pushing pirate.
- :type pirate: Pirate
- :param game: The current game state.
- :type game: PirateGame
- :return: True if the pirate pushed.
- :rtype: bool
- """
- # Go over all enemies.
- for enemy in game.get_enemy_living_pirates():
- # Check if the pirate can push the enemy.
- if pirate.can_push(enemy):
- # Push enemy!
- pirate.push(enemy, enemy.initial_location)
- # Print a message.
- print 'pirate', pirate, 'pushes', enemy, 'towards', enemy.initial_location
- # Did push.
- return True
- # Didn't push.
- return False
- def move_to_defence(game, PIRATE0, PIRATE1, DEFENCE_PUSH, PIRATE2):
- location_to_go = Location(3486,5305)
- DEFENCE_PUSH = Location(3486,6511)
- for pirate_temp in [PIRATE0, PIRATE1, PIRATE2]:
- if not pirate_temp.get_location().equals(location_to_go):
- pirate_temp.sail(location_to_go)
- else:
- ctr_push = 0
- for pirate_temp in [PIRATE0, PIRATE1, PIRATE2]:
- if pirate_temp.can_push(game.get_enemy_capsule()) :
- ctr_push = ctr_push + 1
- #if ctr_push > 1:
- pirate_temp.push(game.get_enemy_capsule().holder, DEFENCE_PUSH)
- def checkBorders(pirate, game):
- """
- checks if the ship is on a danger of crashing (600 instead of 900 )
- """
- print ("inside checkBorders")
- danger = 600 < pirate.location().col < 5800 and 600 < pirate.location().row < 5800
- if(danger):
- print("Our ship is in danger.")
- return (danger)
- def attack_route(game, capsule_spawn, holder):
- mothership = game.get_my_mothership()
- capsule = game.get_my_capsule()
- lst = game.get_all_my_pirates()
- for x in lst:
- pushed = False
- if x.turns_to_revive != 0:
- continue
- for en in game.get_enemy_living_pirates():
- if x.can_push(en):
- x.push(en, game.get_enemy_mothership())
- pushed = True
- break
- if not pushed:
- if(x.equals(lst[0]) or x.equals(lst[1]) or x.equals(lst[2])):
- continue
- else:
- for a in lst:
- if (x.in_push_range(a)):
- y = lst.index(a)
- break
- LastLocation = Location(a.get_location().row, a.get_location().col)
- #if(x.has_capsule()):
- # x.max_speed = 10
- #else:
- # x.max_sp#eed = 200
- if(x.has_capsule() and (x.distance(mothership)+100 <= lst[y].distance(mothership))):
- x.sail(LastLocation)
- if(holder == None):
- x.sail(capsule)
- else:
- x.sail(mothership)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement