Skip to content

timastras9/java-recursion-darpa-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DARPA Drone Dispatch — Recursive Nearest-Drone Selector with AI Decisioning

A Java program that demonstrates recursion finding the smallest value in an array, framed as a real-world problem: a DARPA-style autonomous drone swarm needs to dispatch the drone closest to a target. Pure recursion solves the geometry; xAI's Grok then analyzes the full swarm and returns a structured tactical decision (action / primary / backup / risk / ETA) which the program parses and executes — color-coded orders, ASCII tactical map, and a timestamped audit log.

Built as a CSC263 (Data Structures / Recursion) assignment, then expanded into a portfolio piece.


What it shows

  • Two recursive algorithms for finding the minimum of an array:
    • Linear head-vs-rest recursion — O(n) call depth
    • Divide-and-conquer recursion — O(log n) call depth
  • Iterative baseline that cross-checks both recursive answers.
  • Call tracing that prints every recursive descent and combine step so the stack-unwind is visible in the terminal.
  • ASCII tactical map of the battlefield (drones as letters, target as X, primary drone in red, AI-chosen backup in magenta).
  • Agentic AI layer: Grok receives the full swarm state and replies in a strict structured format (ACTION / PRIMARY / BACKUP / ETA_MIN / RISK / REASONING). The program parses the reply and acts on it — color-coded orders, re-rendered map, and an append-only dispatch_log.txt audit trail.
  • Side-by-side timing comparison: local Java recursion (microseconds) vs Grok API round-trip (seconds, mostly network).
  • Asymptotic-complexity benchmark across array sizes from 100 to 500,000. Linear recursion runs on a dedicated 64 MB-stack thread so it completes cleanly at every size — a textbook example of properly sizing thread stacks in production Java.

Quick start

macOS / Linux

git clone https://github.com/timastras9/java-recursion-darpa-demo.git
cd java-recursion-darpa-demo
cp .env.example .env        # paste your xAI key inside
./run.sh

Windows

git clone https://github.com/timastras9/java-recursion-darpa-demo.git
cd java-recursion-darpa-demo
copy .env.example .env
notepad .env                :: paste your xAI key, save
run.bat

Manual (if you prefer)

javac RecursiveMin/*.java
java -cp . RecursiveMin.DroneDispatch

Without a Grok key the program still runs end-to-end; the AI decision step prints (Grok offline) and falls back to the recursive geometric pick.


Requirements

  • Java 11 or newer (developed and tested on Java 25; only uses the JDK standard library — no Maven, no Gradle, no external dependencies).
  • An xAI API key (free tier works). Get one at https://console.x.ai/

Architecture

RecursiveMin/
├── DroneDispatch.java   # recursion algorithms + tactical map + benchmark + decision pipeline
└── GrokClient.java      # tiny xAI Grok REST wrapper (no SDK, just java.net.http)

Two files. No build system. The whole thing is ~900 lines of commented Java that you can read top to bottom in one sitting.

Recursion structure

Method Strategy Stack depth
findMinLinear Head-vs-rest O(n)
findMinDivideConquer Split in half, recurse, combine O(log n)
findMinIterative Simple loop (correctness cross-check) O(1)
findMinLinearOnBigStack Wraps linear in a 64 MB-stack thread safe past 500k

Each recursive method documents its base case and recursive case explicitly in the source.

Agentic decision flow

  1. Recursion computes the geometrically nearest drone.
  2. The full swarm state + target + recursive pick are serialized into a prompt for Grok.
  3. Grok replies in a strict line-based schema (ACTION:, PRIMARY:, BACKUP:, ETA_MIN:, RISK:, REASONING:).
  4. The program parses the reply, validates callsigns against the swarm, and executes: prints color-coded orders, redraws the map with the backup highlighted, and appends a timestamped entry to dispatch_log.txt.

Tech stack

  • Java 11+ (JDK standard library only — no external deps)
  • xAI Grok API (grok-4.3) via java.net.http.HttpClient
  • ANSI escape codes for color
  • .env file loader built from scratch (no dotenv library needed)

Why this exists

The assignment was a basic "recursive minimum of an array." I wanted to ground it in a real problem — picking the nearest of N drones to a target is exactly that, plus it makes the answer visceral. The AI layer turns the geometry answer into a tactical decision a human commander would actually make.


License

MIT — do whatever you want with it.


Author

Timothy Astras · github.com/timastras9


AI assistance disclosure

All original ideas for this program — the topic, the choice of two recursive strategies, the ASCII tactical map, the structured-decision AI integration, the asymptotic benchmark — are my own. Claude Code (Anthropic) was used as a coding assistant to help implement those ideas in Java. I directed every step, reviewed every line, ran the program, and verified the output.

About

Recursive nearest-drone selector with AI-driven tactical decisioning. Java demo of two recursion strategies (linear & divide-and-conquer) + xAI Grok integration. CSC263 / portfolio.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors