KatInterview

Autonomous Drone Navigation in Dynamic Canyons

Dynamic ProgrammingModel answer
MediumModel answerDynamic Programmingdynamic-programminglookahead-searchsimulation

Last updated

Design a deterministic per-tick controller for a thruster-driven drone navigating procedurally generated obstacle canyons using lookahead simulation.

You are tasked with engineering a flight controller for a probe navigating an uncharted subterranean canyon. The probe advances horizontally at a uniform velocity. Environmental gravity continuously accelerates the probe downward. Its sole mechanical control is an upward impulse thruster: engaging the thruster instantly resets the vertical velocity to a fixed upward magnitude (it does not additively increment velocity).

The canyon walls contain rectangular passages at varying elevations. Colliding with a wall boundary, the floor ($y \le 0$), or the ceiling ($y \ge 120$) results in instantaneous structural destruction.

Write a deterministic decision module that operates on a per-tick cadence and returns a boolean flag (True to fire thruster, False to coast). Your controller will be evaluated against hundreds of randomized, un-annotated canyons with varying gap dimensions, wall spacings, and vertical shifts.

Physics and Environment Constants

Each tick:
    if thrust_engaged:
        vy = LIFT
    else:
        vy = max(vy - GRAVITY, MAX_FALL)
    
    y = y + vy
    x = x + SPEED

GRAVITY  = 0.6
LIFT     = 4.5
MAX_FALL = -8.0
SPEED    = 3.0

PROBE_RADIUS = 3.0
FLOOR_Y      = 0.0
CEILING_Y    = 120.0

Collision condition:
    y - PROBE_RADIUS <= FLOOR_Y  OR  y + PROBE_RADIUS >= CEILING_Y
    OR
    For any wall with horizontal extent [x0, x1]:
        if probe_x_range [x - RADIUS, x + RADIUS] overlaps [x0, x1] AND
        (y - RADIUS < gap_low  OR  y + RADIUS > gap_high)

Data Structures & Interface

from dataclasses import dataclass

@dataclass(frozen=True)
class Wall:
    x0: float   # Left boundary face
    x1: float   # Right boundary face
    low: float  # Bottom height of passage
    high: float # Top height of passage

@dataclass(frozen=True)
class Drone:
    x: float
    y: float
    vy: float

class Autopilot:
    def decide(self, drone: Drone, walls: list[Wall]) -> bool:
        ...

walls is provided pre-sorted by x0 and contains only remaining upcoming obstacles.

Example Scenario

Initial State: Drone(x=0.0, y=60.0, vy=0.0)
Walls: 
  - Wall(x0=60,  x1=75,  low=80, high=110)  # High gap
  - Wall(x0=120, x1=135, low=10, high=40)   # Low gap immediately following
  - Wall(x0=180, x1=195, low=85, high=113)  # High gap

Expected Result: Controller returns control signals per tick that successfully traverse all 3 obstacles without collision.

Technical Constraints

  • Execution time must remain significantly below $10\text{ ms}$ per decision step.
  • Passage gaps are guaranteed to be $\ge 26.0$ units tall. Wall thickness is $18.0$ units. Inter-wall distances range from $60.0$ to $90.0$ units.
  • Decision function must be strictly deterministic.

Hints

Hint 1

Rule-based greedy heuristics fail because preparing for a dramatic drop or rise requires executing actions dozens of ticks before reaching the obstacle.

Hint 2

Because physical movement rules and collision boundaries are fully known, treat control selection as forward trajectory simulation.

Hint 3

The decision space branches binary at each tick ($2^N$). Use dynamic programming/memoization on discretized state tuple (depth, round(y), round(vy)) to keep performance well within time constraints.