Files
SirRoboGarage/tools/robocode_shim/make_botdir.sh
T
SirStone fe8b1eddff Add curated legacy Robocode roster (28 bots) and Tank Royale booter
Curated roster: 34 classic-Robocode archives were downloaded, measured in real
Tank Royale battles and curated to 28 usable bots, now in legacy_bots/<Name>/
(<Name>.jar + <Name>.json + <Name>.sh) with checksums in MANIFEST.sha256.
Six were dropped as NOT_USEFUL and deleted from tr_bots/_salvage/legacy_bots/
and tr_bots/_salvage/tr_wrappers/, with the rationale recorded in
legacy_bots/README.md and tools/robocode_shim/LEGACY_BOTS.md:

  - Nene, Seraphim  - Azuma-framework melee bots, completely inert (0 scans,
                      0 shots); getRobotRunnable() returns null so the shim has
                      no driver path for them.
  - Aurora          - fires 6 shots and crawls.
  - FloodMini, LightningBug, Aristocles - near-stationary turrets: they scan and
                      fire but land 0 hits and take 10+ hits every round.

DrussGT is the reference bot and is deliberately NOT in legacy_bots/: it lives in
tr_bots/DrussGT and is now vendored with its sources under
tools/robocode_shim/vendor/drussgt/.

Repo-relative paths replace /tmp: every <Name>.sh resolves the shim and the
vendor jars via $REPO (../..), and none hardcodes a server URL, a /tmp data
path, or anything under ~/Downloads. SERVER_URL/SERVER_SECRET come from the
environment, which the booter populates from its own -Dserver.url /
-Dsystem.secret system properties.

Booter: tools/booter/robocode-tankroyale-booter-0.35.5-all.jar, copied from a
local tank-royale build, plus a README covering the real CLI. Note the command
is `boot`; the upstream README's `run` is stale. Verified it discovers all 28
kept bots via both `dir` and `info`.

Licensing: every third-party jar here reads "not stated in jar", and DrussGT is
GPL. The repo owner has explicitly waived this - the repository is PRIVATE and
lives on their own LAN. Do not mirror or redistribute without revisiting that.

.gitignore flipped back to tracking legacy_bots/**/*.jar; an over-broad *.jar
rule already cost us the only copy of DrussGT.jar once.
2026-10-04 22:18:28 +02:00

151 lines
5.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Generate a Tank Royale bot directory that boots a classic Robocode robot
# through the robocode_shim bridge.
#
# tools/robocode_shim/make_botdir.sh [TARGET|NAME] \
# [--class FQCN] [--jar PATH] [--name DISPLAY] \
# [--version V] [--authors A] [--desc D] [--country CC] [--gametypes G]
#
# The first positional argument may be either
# * a directory path (legacy form, e.g. /tmp/tr_bots/DrussGT), or
# * a bare bot name, in which case the dir is /tmp/tr_bots/<NAME>.
# With no arguments at all it reproduces the original DrussGT directory.
#
# The generated directory contains only text files (<dir>.json + <dir>.sh); the
# third-party jars stay outside the repo and are referenced by absolute path.
#
# Defaults (so the original no-arg DrussGT invocation is byte-for-byte usable):
# --class jk.mega.DrussGT
# --jar $DRUSSGT_JAR (/tmp/drussgt/DrussGT.jar)
# display name = bot-dir basename, version parsed from the jar name (or 3.1.4159)
#
# Data-directory isolation: the generated launcher sets SHIM_DATA to a fresh
# per-process mktemp directory unless the caller already provided SHIM_DATA /
# DRUSSGT_DATA. Two bots (or two concurrent battles) therefore can never share
# or clobber one classic data directory.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET=""
CLASS=""
JAR=""
DISPLAY=""
VERSION=""
AUTHORS=""
DESC=""
COUNTRY="se"
GAMETYPES="classic,1v1"
if [[ $# -gt 0 && "${1}" != --* ]]; then
TARGET="$1"; shift
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--class) CLASS="$2"; shift 2;;
--jar) JAR="$2"; shift 2;;
--name) DISPLAY="$2"; shift 2;;
--version) VERSION="$2"; shift 2;;
--authors) AUTHORS="$2"; shift 2;;
--desc) DESC="$2"; shift 2;;
--country) COUNTRY="$2"; shift 2;;
--gametypes) GAMETYPES="$2"; shift 2;;
-h|--help) sed -n '2,30p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0;;
*) echo "unknown argument: $1" >&2; exit 2;;
esac
done
# --- resolve target dir + name (legacy forms preserved) ---
if [[ -z "$TARGET" ]]; then
TARGET="/tmp/tr_bots/DrussGT"
elif [[ "$TARGET" != */* ]]; then
TARGET="/tmp/tr_bots/$TARGET"
fi
DIR_NAME="$(basename "$TARGET")"
DRUSSGT_JAR="${DRUSSGT_JAR:-$HERE/vendor/drussgt/DrussGT.jar}"
CLASS="${CLASS:-jk.mega.DrussGT}"
JAR="${JAR:-$DRUSSGT_JAR}"
NAME="${DISPLAY:-$DIR_NAME}"
# --- defaults that keep the DrussGT case identical to the old script ---
if [[ -z "$VERSION" ]]; then
if [[ "$CLASS" == "jk.mega.DrussGT" ]]; then
VERSION="3.1.4159"
else
stem="$(basename "$JAR")"; stem="${stem%.jar}"
if [[ "$stem" == *_* ]]; then VERSION="${stem##*_}"; else VERSION="1.0"; fi
fi
fi
[[ -n "$AUTHORS" ]] || { if [[ "$CLASS" == "jk.mega.DrussGT" ]]; then AUTHORS="Jacob"; else AUTHORS="unknown"; fi; }
[[ -n "$DESC" ]] || { if [[ "$CLASS" == "jk.mega.DrussGT" ]]; then
DESC="Real classic DrussGT running on Tank Royale via the robocode_shim bridge"
else
DESC="Classic Robocode robot ${CLASS} running on Tank Royale via the robocode_shim bridge"
fi; }
GAMETYPES_JSON="$(printf '%s' "$GAMETYPES" | sed 's/,/\", \"/g')"
ROBOCODE_JAR="${ROBOCODE_JAR:-$HERE/vendor/robocode.jar}"
TR_BOT_API_JAR="${TR_BOT_API_JAR:-$HOME/Downloads/sample-bots-java-1.0.2/lib/robocode-tankroyale-bot-api-1.0.2.jar}"
OUT="${OUT:-$HERE/out}"
EXTRA_CP="${SHIM_EXTRA_CP:-}"
EXTRA_LINE=""
[[ -n "$EXTRA_CP" ]] && EXTRA_LINE="export SHIM_EXTRA_CP=\"$EXTRA_CP\""
mkdir -p "$TARGET"
cat > "$TARGET/$DIR_NAME.json" <<JSON
{
"name": "$NAME",
"version": "$VERSION",
"authors": ["$AUTHORS"],
"description": "$DESC",
"homepage": "",
"countryCodes": ["$COUNTRY"],
"gameTypes": ["$GAMETYPES_JSON"],
"platform": "JVM",
"programmingLang": "Java 8"
}
JSON
# The Tank Royale bot API reads bot identity from BOT_* environment variables.
# When the TR booter launches this directory it supplies them (derived from the
# .json above), but running this script BY HAND does not - and the API then
# rejects the handshake with "Required bot property 'name' is missing".
# Exporting them here makes the script work standalone as well.
#
# SHIM_BOT_CLASS / SHIM_BOT_JAR select the hosted classic robot. SHIM_DATA is a
# fresh per-process directory by default: two bots (or two concurrent battles)
# can never share or clobber the same classic data directory.
cat > "$TARGET/$DIR_NAME.sh" <<SH
#!/bin/sh
cd "\$(dirname "\$0")"
# Hosted classic robot selection - keep in sync with $DIR_NAME.json
export SHIM_BOT_CLASS="$CLASS"
export SHIM_BOT_JAR="$JAR"
$EXTRA_LINE
: "\${SHIM_DATA:=\${DRUSSGT_DATA:-\$(mktemp -d "\${TMPDIR:-/tmp}/tr_shim_data.XXXXXX")}}"
export SHIM_DATA
# Bot identity - keep in sync with $DIR_NAME.json
export BOT_NAME="$NAME"
export BOT_VERSION="$VERSION"
export BOT_AUTHORS="$AUTHORS"
export BOT_DESCRIPTION="$DESC"
export BOT_HOMEPAGE=""
export BOT_COUNTRY_CODES="$COUNTRY"
export BOT_GAME_TYPES="$GAMETYPES"
export BOT_PLATFORM="JVM"
export BOT_PROG_LANG="Java 8"
exec java -cp "$OUT:$ROBOCODE_JAR:$TR_BOT_API_JAR" robocode_shim.LegacyBotBridge
SH
chmod +x "$TARGET/$DIR_NAME.sh"
echo "bot dir ready: $TARGET"
echo " $TARGET/$DIR_NAME.json"
echo " $TARGET/$DIR_NAME.sh"
echo " class: $CLASS"
echo " jar: $JAR"
echo " (classpath: $OUT:$ROBOCODE_JAR:$TR_BOT_API_JAR)"