#!/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/. # With no arguments at all it reproduces the original DrussGT directory. # # The generated directory contains only text files (.json + .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:-/tmp/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:-/tmp/robocode/install/libs/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" < "$TARGET/$DIR_NAME.sh" <