Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for ship in game_map.get_me().all_ships():
- nearestPlanet = None
- if ship.docking_status != ship.DockingStatus.UNDOCKED:
- # Skip this ship
- continue
- logging.info("about to nearest")
- # nearest unowned planet to ship
- nearestPlanet = hlt.Gen.nearest_free_planet_to_ship(ship, game_map)
- logging.info("nearestPlanet instantiated")
- logging.info("Check ship actions")
- # If we can dock, let's (try to) dock. If two ships try to dock at once, neither will be able to.
- if nearestPlanet != None and ship.can_dock(nearestPlanet):
- logging.info("About to attempt a docking move")
- # We add the command by appending it to the command_queue
- command_queue.append(ship.dock(nearestPlanet))
- elif nearestPlanet == None:
- #after all the planets are taken ships need to make thrustmoves to attack
- #lets try attacking docked enemy ships
- enemyShip = hlt.Gen.nearest_docked_enemy(ship, game_map, me)
- logging.info(enemyShip)
- if enemyShip != None:
- logging.info("found an enemy ship!")
- # logging.info("num obstacles between" + game_map.obstacles_between(game_map, ship, enemyShip, entity.Ship))
- # if len(game_map.obstacles_between(game_map, ship, enemyShip, entity.Ship)) == 0:
- # logging.info("no obstacles between me and enemy")
- # myThrustAngle = ship.calculate_angle_between(enemyShip)
- # navigate_command = ship.thrust(hlt.constants.MAX_SPEED, myThrustAngle)
- # else:
- # logging.info("There were obstacles between me and enemy")
- navigate_command = ship.navigate(enemyShip, game_map, speed=hlt.constants.MAX_SPEED, ignore_ships=True)
- if navigate_command:
- logging.info("I am now trying to blow up enemy")
- command_queue.append(navigate_command)
- else:
- # If we can't dock, we move towards the closest empty point near this planet (by using closest_point_to)
- # with constant speed. Don't worry about pathfinding for now, as the command will do it for you.
- # We run this navigate command each turn until we arrive to get the latest move.
- # Here we move at half our maximum speed to better control the ships
- # In order to execute faster we also choose to ignore ship collision calculations during navigation.
- # This will mean that you have a higher probability of crashing into ships, but it also means you will
- # make move decisions much quicker. As your skill progresses and your moves turn more optimal you may
- # wish to turn that option off.
- logging.info(nearestPlanet)
- navigate_command = ship.navigate(ship.closest_point_to(nearestPlanet), game_map, speed=hlt.constants.MAX_SPEED, ignore_ships=False)
- # If the move is possible, add it to the command_queue (if there are too many obstacles on the way
- # or we are trapped (or we reached our destination!), navigate_command will return null;
- # don't fret though, we can run the command again the next turn)
- if navigate_command:
- logging.info("I am now trying to get near a planet")
- command_queue.append(navigate_command)
- break
- # Send our set of commands to the Halite engine for this turn
- game.send_command_queue(command_queue)
- logging.info("sent command_queue")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement