airesources/Ruby/hlt/ship.rb
# target: The Entity to which you will navigate
# map: The map of the game, from which obstacles will be extracted
# speed: The (max) speed to navigate. If the obstacle is near, it will adjust
# avoid_obstacles: Whether to avoid the obstacles in the way (simple
#                  pathfinding).
# max_corrections: The maximum number of degrees to deviate per turn while
#                  trying to pathfind. If exceeded returns None.
# angular_step: The degree difference to deviate if the path has obstacles
# ignore_ships: Whether to ignore ships in calculations (this will make your
#               movement faster, but more precarious)
# ignore_planets: Whether to ignore planets in calculations (useful if you
#                 want to crash onto planets)
# return: The command trying to be passed to the Halite engine or nil if
#         movement is not possible within max_corrections degrees.
The Entity to which you will navigate
map: The map of the game, from which obstacles will be extracted
speed: The (max) speed to navigate. If the obstacle is near, it will adjust
avoid_obstacles: Whether to avoid the obstacles in the way (simple
pathfinding).
max_corrections: The maximum number of degrees to deviate per turn while
trying to pathfind. If exceeded returns None.
angular_step: The degree difference to deviate if the path has obstacles
ignore_ships: Whether to ignore ships in calculations (this will make your
movement faster, but more precarious)
ignore_planets: Whether to ignore planets in calculations (useful if you
want to crash onto planets)
return: The command trying to be passed to the Halite engine or nil if
movement is not possible within max_corrections degrees.
The Entity to which you will navigate map : The map of the game from which obstacles will be extracted speed : The ( max ) speed to navigate . If the obstacle is near it will adjust avoid_obstacles : Whether to avoid the obstacles in the way ( simple pathfinding ) . max_corrections : The maximum number of degrees to deviate per turn while trying to pathfind . If exceeded returns None . angular_step : The degree difference to deviate if the path has obstacles ignore_ships : Whether to ignore ships in calculations ( this will make your movement faster but more precarious ) ignore_planets : Whether to ignore planets in calculations ( useful if you want to crash onto planets ) return : The command trying to be passed to the Halite engine or nil if movement is not possible within max_corrections degrees .
def navigate(target, map, speed, avoid_obstacles: true, max_corrections: 90,
              angular_step: 1, ignore_ships: false, ignore_planets: false)
    return if max_corrections <= 0
    distance = calculate_distance_between(target)
    angle = calculate_deg_angle_between(target)
    ignore = []
    ignore << :ships if ignore_ships
    ignore << :planets if ignore_planets
    if avoid_obstacles && map.obstacles_between(self, target, ignore).length > 0
      delta_radians = (angle + angular_step)/180.0 * Math::PI
      new_target_dx = Math.cos(delta_radians) * distance
      new_target_dy = Math.sin(delta_radians) * distance
      new_target = Position.new(x + new_target_dx, y + new_target_dy)
      return navigate(new_target, map, speed,
                      avoid_obstacles: true,
                      max_corrections: max_corrections-1,
                      angular_step: angular_step)
    end
    speed = distance >= speed ? speed : distance
    thrust(speed, angle)
  end
def navigate ( target , map , speed , avoid_obstacles : true , max_corrections : 90 , angular_step : 1 , ignore_ships : false , ignore_planets : false ) return if max_corrections <= 0 distance = calculate_distance_between ( target ) angle = calculate_deg_angle_between ( target ) ignore = [ ] ignore << :ships if ignore_ships ignore << :planets if ignore_planets if avoid_obstacles && map . obstacles_between ( self , target , ignore ) . length > 0 delta_radians = ( angle + angular_step ) / 180.0 * Math :: PI new_target_dx = Math . cos ( delta_radians ) * distance new_target_dy = Math . sin ( delta_radians ) * distance new_target = Position . new ( x + new_target_dx , y + new_target_dy ) return navigate ( new_target , map , speed , avoid_obstacles : true , max_corrections : max_corrections - 1 , angular_step : angular_step ) end speed = distance >= speed ? speed : distance thrust ( speed , angle ) end
target: The Entity to which you will navigate
map: The map of the game, from which obstacles will be extracted
speed: The (max) speed to navigate.
target : The Entity to which you will navigate map : The map of the game from which obstacles will be extracted speed : The ( max ) speed to navigate .
target
<not_specific>
map
<not_specific>
speed
<not_specific>
avoid_obstacles
<not_specific>
max_corrections
<not_specific>
angular_step
<not_specific>
ignore_ships
<not_specific>
ignore_planets
<not_specific>