Skip to main content

RoboCode Reborn

0
0 t/f

About

WartHogNG is a Robocode bot — an autonomous tank AI that fights other bots in a 2D arena. It evolved from WartHog, a bot I wrote in 2001 with a law-of-sines firing solution. The NG version replaces that with KNN adaptive targeting: a KD-tree that learns enemy movement patterns in real time and predicts where to shoot based on the most similar situations it has seen before.

How WartHogNG Works

Targeting: KNN Adaptive Gun

Every time WartHogNG fires, it records a 6-dimensional snapshot of the situation: distance, lateral velocity, advancing velocity, time since last direction change, wall proximity, and acceleration. When the bullet arrives (or misses), it records the actual angular offset the enemy ended up at — the guess factor.

To aim the next shot, it queries the KD-tree for the 8 most similar past situations and takes a weighted average of their guess factors. Early in the battle it blends with a linear predictor; after ~20 observations it relies entirely on KNN.

Observe 6D situation vector Query KD-Tree K=8 nearest neighbors Predict GF weighted avg of neighbors Fire GF → firing angle Record actual GF when bullet arrives scan search aim shoot learn

The 6D Feature Space

DimensionRangeWhy it matters
Distance0–1Closer enemies have less time to dodge
Lateral velocity−1–1How fast enemy moves sideways relative to us
Advancing velocity−1–1How fast enemy approaches or retreats
Time since dir change0–1Longer runs predict continued movement
Wall proximity0–1Wall-adjacent enemies have limited escape
Acceleration−1–1Speeding up vs slowing down changes dodge trajectory

Movement: Tight Orbit + Bullet Dodge

WartHogNG orbits the target tangentially at 120–170px — close enough for high-damage shots, far enough to have dodge time. When the orbit drifts outside the band, the heading angles inward or outward to correct.

Three movement tricks layer on top:

Stalemate Prevention

If WartHogNG detects it's stuck in a repetitive orbit (same grid cell visited 4+ times in 200 ticks with no radar contact), it abandons the orbit and heads toward the field center while spinning the radar to re-acquire the target.

170px 120px Enemy NG tangent orbit bullet dodge! orbit band: 120–170px

Origin

The original WartHog was a 2001 Java bot using law-of-sines predictive targeting. WartHogNG keeps the orbit movement but replaces the targeting with a KNN adaptive gun. The simulation above is a JavaScript port with a full physics engine matching Robocode's rules.

The Opponents

15 competitive bots in the live simulation, plus 15 historical bots described below. Win rates from a 200-match tournament per opponent using pure KNN targeting (no mimicry).

Nemesis

Hard (< 80%)

Competitive (80–92%)

Dominated (93–100%)

Historical Interest

These bots pioneered important Robocode techniques but WartHogNG beats them consistently (93–100%). They're not in the live simulation but their strategies shaped competitive Robocode.