Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. for ship in game_map.get_me().all_ships():
  2. nearestPlanet = None
  3. if ship.docking_status != ship.DockingStatus.UNDOCKED:
  4. # Skip this ship
  5. continue
  6.  
  7. logging.info("about to nearest")
  8. # nearest unowned planet to ship
  9. nearestPlanet = hlt.Gen.nearest_free_planet_to_ship(ship, game_map)
  10. logging.info("nearestPlanet instantiated")
  11.  
  12. logging.info("Check ship actions")
  13. # If we can dock, let's (try to) dock. If two ships try to dock at once, neither will be able to.
  14. if nearestPlanet != None and ship.can_dock(nearestPlanet):
  15. logging.info("About to attempt a docking move")
  16. # We add the command by appending it to the command_queue
  17. command_queue.append(ship.dock(nearestPlanet))
  18.  
  19. elif nearestPlanet == None:
  20. #after all the planets are taken ships need to make thrustmoves to attack
  21. #lets try attacking docked enemy ships
  22. enemyShip = hlt.Gen.nearest_docked_enemy(ship, game_map, me)
  23. logging.info(enemyShip)
  24. if enemyShip != None:
  25. logging.info("found an enemy ship!")
  26. # logging.info("num obstacles between" + game_map.obstacles_between(game_map, ship, enemyShip, entity.Ship))
  27. # if len(game_map.obstacles_between(game_map, ship, enemyShip, entity.Ship)) == 0:
  28. # logging.info("no obstacles between me and enemy")
  29. # myThrustAngle = ship.calculate_angle_between(enemyShip)
  30. # navigate_command = ship.thrust(hlt.constants.MAX_SPEED, myThrustAngle)
  31.  
  32. # else:
  33. # logging.info("There were obstacles between me and enemy")
  34. navigate_command = ship.navigate(enemyShip, game_map, speed=hlt.constants.MAX_SPEED, ignore_ships=True)
  35.  
  36. if navigate_command:
  37. logging.info("I am now trying to blow up enemy")
  38. command_queue.append(navigate_command)
  39.  
  40. else:
  41. # If we can't dock, we move towards the closest empty point near this planet (by using closest_point_to)
  42. # with constant speed. Don't worry about pathfinding for now, as the command will do it for you.
  43. # We run this navigate command each turn until we arrive to get the latest move.
  44. # Here we move at half our maximum speed to better control the ships
  45. # In order to execute faster we also choose to ignore ship collision calculations during navigation.
  46. # This will mean that you have a higher probability of crashing into ships, but it also means you will
  47. # make move decisions much quicker. As your skill progresses and your moves turn more optimal you may
  48. # wish to turn that option off.
  49. logging.info(nearestPlanet)
  50. navigate_command = ship.navigate(ship.closest_point_to(nearestPlanet), game_map, speed=hlt.constants.MAX_SPEED, ignore_ships=False)
  51. # If the move is possible, add it to the command_queue (if there are too many obstacles on the way
  52. # or we are trapped (or we reached our destination!), navigate_command will return null;
  53. # don't fret though, we can run the command again the next turn)
  54. if navigate_command:
  55. logging.info("I am now trying to get near a planet")
  56. command_queue.append(navigate_command)
  57. break
  58.  
  59. # Send our set of commands to the Halite engine for this turn
  60. game.send_command_queue(command_queue)
  61. logging.info("sent command_queue")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement