tools/raw_recorder + tr_bots/_salvage: recorder source and the legacy port
tools/raw_recorder/RawRecord.java + shadow/GameRecorder.java the observer
that writes the .battle.gz corpora in data/ (gitignored, regenerable)
tools/raw_recorder/query.py, sample_outline.md query helpers
and the shape of a capture
tr_bots/_salvage/ the port audit:
portaudit/{methods,static}.py, shim/, and the tr_wrappers/*.json + *.sh
for 29 rescued legacy bots, with legacy_bots/MANIFEST.sha256
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import dev.robocode.tankroyale.runner.BattleHandle;
|
||||
import dev.robocode.tankroyale.runner.BattleRunner;
|
||||
import dev.robocode.tankroyale.runner.BattleSetup;
|
||||
import dev.robocode.tankroyale.runner.BotEntry;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Runs a battle with the runner's built-in recording enabled
|
||||
* (BattleRunner.Builder.enableRecording -> GameRecorder) and nothing else.
|
||||
* The raw observer stream lands in DIR as game-<timestamp>.battle.gz
|
||||
* (gzipped ND-JSON, one observer message per line):
|
||||
*
|
||||
* gunzip -c DIR/game-*.battle.gz > /tmp/raw.jsonl
|
||||
*/
|
||||
public final class RawRecord {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String dirArg = "/tmp/rawrec";
|
||||
int roundsArg = 2;
|
||||
List<Path> bots = new ArrayList<>();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
switch (args[i]) {
|
||||
case "--dir" -> dirArg = args[++i];
|
||||
case "--rounds" -> roundsArg = Integer.parseInt(args[++i]);
|
||||
case "--bot" -> bots.add(Path.of(args[++i]));
|
||||
default -> { System.err.println("Unknown arg: " + args[i]); System.exit(2); }
|
||||
}
|
||||
}
|
||||
final String dir = dirArg;
|
||||
final int rounds = roundsArg;
|
||||
if (bots.isEmpty()) { System.err.println("--bot <dir> required (repeatable)"); System.exit(2); }
|
||||
|
||||
List<BotEntry> entries = new ArrayList<>();
|
||||
for (Path b : bots) entries.add(BotEntry.of(b));
|
||||
|
||||
try (BattleRunner runner = BattleRunner.create(
|
||||
b -> b.embeddedServer().suppressServerOutput().enableRecording(Path.of(dir)))) {
|
||||
BattleSetup setup = BattleSetup.classic(s -> {
|
||||
s.setNumberOfRounds(rounds);
|
||||
s.setDefaultTurnsPerSecond(-1);
|
||||
});
|
||||
try (BattleHandle h = runner.startBattleAsync(setup, entries)) {
|
||||
Object owner = new Object();
|
||||
h.getOnRoundEnded().on(owner, e -> System.out.println("[raw] round " + e.getRoundNumber() + " done"));
|
||||
var res = h.awaitResults();
|
||||
System.out.println("[raw] results: " + res.getResults());
|
||||
}
|
||||
}
|
||||
System.out.println("[raw] recording in " + dir);
|
||||
}
|
||||
}
|
||||
Executable
+131
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Query / verify a raw Tank Royale battle recording (.battle.gz, gzipped ND-JSON).
|
||||
|
||||
The recording is the UNFILTERED raw observer stream: one verbatim server message per line.
|
||||
Each line is a JSON object with a top-level "type". TickEventForObserver lines carry
|
||||
turnNumber, roundNumber, botStates[], bulletStates[], events[].
|
||||
|
||||
Usage:
|
||||
# integrity report (turn continuity, bot presence, event histogram)
|
||||
query.py --verify FILE.battle.gz
|
||||
|
||||
# compact tick table for a turn range (any range, any recording)
|
||||
query.py FILE.battle.gz --range 300 340
|
||||
query.py FILE.battle.gz --range 300 340 --round 2
|
||||
query.py FILE.battle.gz --auto 40 # 40 ticks around the first bullet being fired
|
||||
"""
|
||||
import argparse, collections, gzip, json, sys
|
||||
|
||||
|
||||
def read(path):
|
||||
op = gzip.open if path.endswith(".gz") else open
|
||||
with op(path, "rt") as fh:
|
||||
for line in fh:
|
||||
line = line.strip()
|
||||
if line:
|
||||
try:
|
||||
yield json.loads(line)
|
||||
except json.JSONDecodeError:
|
||||
yield {"type": "<unparseable>"}
|
||||
|
||||
|
||||
def load(path, rnd=None):
|
||||
ticks, top = [], collections.Counter()
|
||||
for m in read(path):
|
||||
top[m.get("type")] += 1
|
||||
if m.get("type") == "TickEventForObserver" and (rnd is None or m.get("roundNumber") == rnd):
|
||||
ticks.append(m)
|
||||
return ticks, top
|
||||
|
||||
|
||||
def verify(path, ticks, top):
|
||||
print("== top-level types on the wire ==")
|
||||
for k, v in top.most_common():
|
||||
print(f" {v:7d} {k}")
|
||||
|
||||
turns = [t["turnNumber"] for t in ticks]
|
||||
print("\n== turnNumber continuity ==")
|
||||
if not turns:
|
||||
print(" NO TICKS"); return
|
||||
print(f" count={len(turns)} min={min(turns)} max={max(turns)} distinct={len(set(turns))}")
|
||||
per_round = collections.defaultdict(list)
|
||||
for t in ticks:
|
||||
per_round[t["roundNumber"]].append(t["turnNumber"])
|
||||
gaps = dups = 0
|
||||
for r, ts in sorted(per_round.items()):
|
||||
s = sorted(ts)
|
||||
g = [(a, b) for a, b in zip(s, s[1:]) if b - a != 1]
|
||||
d = [k for k, v in collections.Counter(ts).items() if v > 1]
|
||||
gaps += sum(b - a - 1 for a, b in g)
|
||||
dups += len(d)
|
||||
print(f" round {r}: {len(s)} turns [{s[0]}..{s[-1]}] gaps={g if g else 'NONE'} dups={d if d else 'NONE'}")
|
||||
print(f" VERDICT: {'CONTIGUOUS, no drops' if gaps == 0 and dups == 0 else f'BROKEN ({gaps} missing turns, {dups} duplicated)'}")
|
||||
|
||||
print("\n== bots ==")
|
||||
ids = collections.Counter()
|
||||
for t in ticks:
|
||||
ids[tuple(sorted(b["id"] for b in t["botStates"]))] += 1
|
||||
for b in t["botStates"]:
|
||||
pass
|
||||
names = {b["id"]: b["name"] for t in ticks for b in t["botStates"]}
|
||||
for k, v in ids.items():
|
||||
print(f" bot-id-set {k} ({', '.join(names.get(i, '?') for i in k)}): {v}/{len(ticks)} ticks")
|
||||
owners = collections.Counter()
|
||||
for t in ticks:
|
||||
owners[tuple(sorted(bs.get("ownerId") for bs in t["bulletStates"]))] += 1
|
||||
print(f" bulletStates ownerId sets: {dict(owners)} (empty = no bullets in flight)")
|
||||
|
||||
print("\n== events[] histogram (inner) ==")
|
||||
h = collections.Counter()
|
||||
for t in ticks:
|
||||
for e in t["events"]:
|
||||
h[e.get("type")] += 1
|
||||
for k, v in h.most_common():
|
||||
print(f" {v:7d} {k}")
|
||||
for want in ["BulletFiredEvent", "BulletHitBotEvent", "BulletHitWallEvent",
|
||||
"BulletHitBulletEvent", "ScannedBotEvent", "BotDeathEvent"]:
|
||||
print(f" {'OK ' if h.get(want) else 'MISS'} {want}: {h.get(want, 0)}")
|
||||
|
||||
|
||||
def table(ticks):
|
||||
names = {b["id"]: b["name"][:11] for t in ticks for b in t["botStates"]}
|
||||
print(f"{'turn':>5} {'bots':<26} {'bullets':>7} events")
|
||||
for t in ticks:
|
||||
bs = " | ".join(f"#{b['id']} {names[b['id']]:<11} ({b['x']:6.1f},{b['y']:6.1f}) d={b['direction']:6.1f} g={b['gunDirection']:6.1f}"
|
||||
for b in sorted(t["botStates"], key=lambda x: x["id"]))
|
||||
ev = " ".join(f"{e.get('type')}({','.join(f'{k}={v}' for k, v in sorted(e.items()) if k not in ('type',))})"
|
||||
for e in t["events"]) or "-"
|
||||
print(f"{t['turnNumber']:5d} {bs:<62} {len(t['bulletStates']):7d} {ev}")
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("file")
|
||||
ap.add_argument("--verify", action="store_true")
|
||||
ap.add_argument("--range", nargs=2, type=int, metavar=("LO", "HI"))
|
||||
ap.add_argument("--round", type=int, dest="rnd")
|
||||
ap.add_argument("--auto", type=int, metavar="N", help="N ticks around the first bullet firing")
|
||||
a = ap.parse_args()
|
||||
|
||||
ticks, top = load(a.file, a.rnd)
|
||||
if a.verify:
|
||||
verify(a.file, ticks, top)
|
||||
if a.range:
|
||||
lo, hi = a.range
|
||||
sel = [t for t in ticks if lo <= t["turnNumber"] <= hi]
|
||||
elif a.auto:
|
||||
hit = next((t["turnNumber"] for t in ticks
|
||||
if any(e.get("type") == "BulletFiredEvent" for e in t["events"])), None)
|
||||
if hit is None:
|
||||
sys.exit("no BulletFiredEvent in this recording")
|
||||
sel = [t for t in ticks if hit <= t["turnNumber"] <= hit + a.auto - 1]
|
||||
else:
|
||||
sel = ticks[:40] if not a.verify else []
|
||||
if sel:
|
||||
print(f"\n== ticks {sel[0]['turnNumber']}..{sel[-1]['turnNumber']} "
|
||||
f"(round {sorted({t['roundNumber'] for t in sel})}) ==")
|
||||
table(sel)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,107 @@
|
||||
# Raw Tank Royale recording — human-readable sample
|
||||
|
||||
Source: /tmp/rawrec_unf/game-2026-10-04-21-19-27.battle.gz (319742 B gz, 3238 lines)
|
||||
OscillatorBot vs WaveSurfer, 3 rounds, recorded UNFILTERED.
|
||||
|
||||
## How this file was produced
|
||||
|
||||
cd tools/raw_recorder
|
||||
JAR=/home/davide/Projects/tank-royale/runner/examples/lib/robocode-tankroyale-runner.jar
|
||||
A=../../common_libs/test_framework/adversaries
|
||||
mkdir -p /tmp/rawrec_unf
|
||||
java -cp "shadow-classes:out:$JAR" RawRecord --dir /tmp/rawrec_unf --rounds 3 \
|
||||
--bot $A/OscillatorBot --bot $A/WaveSurfer
|
||||
|
||||
`shadow-classes/` MUST come before the jar: it holds a byte-compatible
|
||||
`dev.robocode.tankroyale.common.recording.GameRecorder` whose RECORDABLE_EVENT_TYPES accepts
|
||||
every type. The stock filter silently dropped `RoundStartedEvent`; the shadow records it.
|
||||
tank-royale itself is untouched.
|
||||
|
||||
## Querying any tick range
|
||||
|
||||
python3 query.py RECORDING.battle.gz --range 300 340 # explicit turn range
|
||||
python3 query.py RECORDING.battle.gz --auto 40 # 40 ticks from a bullet firing
|
||||
python3 query.py RECORDING.battle.gz --verify # full integrity report
|
||||
python3 query.py RECORDING.battle.gz --round 2 --range 100 160
|
||||
|
||||
## Tick table: 40 ticks around OscillatorBot's first shot (turn 33) and its
|
||||
## resolution — BulletHitWallEvent at turn 60.
|
||||
|
||||
== ticks 33..72 (round [1]) ==
|
||||
turn bots bullets events
|
||||
33 #1 WaveSurfer ( 775.9, 397.6) d= 341.1 g= 184.4 | #2 OscillatorB ( 529.9, 94.6) d= 159.0 g= 51.3 1 BulletFiredEvent(bullet={'bulletId': 1, 'ownerId': 2, 'power': 2.0, 'x': 524.321560936505, 'y': 96.27566858659398, 'direction': 44.124617464630376},turnNumber=33)
|
||||
34 #1 WaveSurfer ( 782.0, 395.5) d= 345.1 g= 204.4 | #2 OscillatorB ( 536.4, 92.1) d= 155.0 g= 58.4 1 BotHitWallEvent(turnNumber=34,victimId=1)
|
||||
35 #1 WaveSurfer ( 782.0, 395.5) d= 354.4 g= 224.4 | #2 OscillatorB ( 542.7, 89.2) d= 151.0 g= 65.6 1 -
|
||||
36 #1 WaveSurfer ( 782.0, 395.5) d= 3.6 g= 244.4 | #2 OscillatorB ( 548.8, 85.8) d= 147.0 g= 72.7 1 BotHitWallEvent(turnNumber=36,victimId=1)
|
||||
37 #1 WaveSurfer ( 782.0, 395.5) d= 12.9 g= 264.4 | #2 OscillatorB ( 554.7, 82.0) d= 143.0 g= 79.9 1 -
|
||||
38 #1 WaveSurfer ( 782.0, 395.5) d= 3.6 g= 284.4 | #2 OscillatorB ( 560.3, 77.7) d= 139.0 g= 87.0 1 BotHitWallEvent(turnNumber=38,victimId=1)
|
||||
39 #1 WaveSurfer ( 782.0, 395.5) d= 354.4 g= 304.4 | #2 OscillatorB ( 565.6, 73.2) d= 135.0 g= 94.1 1 -
|
||||
40 #1 WaveSurfer ( 782.0, 395.5) d= 345.1 g= 324.4 | #2 OscillatorB ( 570.5, 68.2) d= 131.0 g= 101.3 1 BotHitWallEvent(turnNumber=40,victimId=1) ScannedBotEvent(direction=131.04623116335074,energy=98.0,scannedBotId=2,scannedByBotId=1,speed=-7.0,turnNumber=40,x=570.5412254446364,y=68.21215577729842)
|
||||
41 #1 WaveSurfer ( 782.0, 395.5) d= 335.9 g= 304.4 | #2 OscillatorB ( 575.1, 62.9) d= 127.0 g= 108.4 1 ScannedBotEvent(direction=335.88278297201384,energy=97.0,scannedBotId=1,scannedByBotId=2,speed=0.0,turnNumber=41,x=782.0,y=395.5463379989983)
|
||||
42 #1 WaveSurfer ( 782.0, 395.5) d= 326.6 g= 284.4 | #2 OscillatorB ( 579.4, 57.3) d= 123.0 g= 88.4 1 BotHitWallEvent(turnNumber=42,victimId=1)
|
||||
43 #1 WaveSurfer ( 782.0, 395.5) d= 317.4 g= 264.4 | #2 OscillatorB ( 583.2, 51.5) d= 118.3 g= 68.4 1 -
|
||||
44 #1 WaveSurfer ( 782.0, 395.5) d= 308.1 g= 244.4 | #2 OscillatorB ( 586.5, 45.3) d= 113.5 g= 48.4 1 BotHitWallEvent(turnNumber=44,victimId=1)
|
||||
45 #1 WaveSurfer ( 782.0, 395.5) d= 298.9 g= 224.4 | #2 OscillatorB ( 589.3, 38.9) d= 108.8 g= 28.4 1 -
|
||||
46 #1 WaveSurfer ( 782.0, 395.5) d= 289.6 g= 204.4 | #2 OscillatorB ( 591.5, 32.3) d= 104.0 g= 8.4 1 BotHitWallEvent(turnNumber=46,victimId=1)
|
||||
47 #1 WaveSurfer ( 782.0, 395.5) d= 280.4 g= 184.4 | #2 OscillatorB ( 593.2, 25.5) d= 99.3 g= 348.4 1 -
|
||||
48 #1 WaveSurfer ( 782.0, 395.5) d= 271.1 g= 164.4 | #2 OscillatorB ( 594.4, 18.6) d= 94.5 g= 328.4 1 BotHitWallEvent(turnNumber=48,victimId=1) ScannedBotEvent(direction=94.54623116335074,energy=98.0,scannedBotId=2,scannedByBotId=1,speed=-7.0,turnNumber=48,x=594.3720873556639,y=18.5720475530427)
|
||||
49 #1 WaveSurfer ( 782.0, 395.5) d= 261.9 g= 184.4 | #2 OscillatorB ( 594.4, 18.0) d= 89.8 g= 308.4 1 BotHitWallEvent(turnNumber=49,victimId=2) ScannedBotEvent(direction=261.88278297201384,energy=97.0,scannedBotId=1,scannedByBotId=2,speed=0.0,turnNumber=49,x=782.0,y=395.5463379989983)
|
||||
50 #1 WaveSurfer ( 781.9, 394.6) d= 252.6 g= 204.4 | #2 OscillatorB ( 594.4, 18.0) d= 80.5 g= 328.4 1 -
|
||||
51 #1 WaveSurfer ( 781.3, 392.6) d= 261.1 g= 224.4 | #2 OscillatorB ( 594.6, 19.0) d= 89.8 g= 348.4 1 -
|
||||
52 #1 WaveSurfer ( 780.8, 389.7) d= 253.4 g= 244.4 | #2 OscillatorB ( 594.6, 21.0) d= 98.3 g= 8.4 1 -
|
||||
53 #1 WaveSurfer ( 779.7, 385.9) d= 246.4 g= 264.4 | #2 OscillatorB ( 594.2, 24.0) d= 106.0 g= 28.4 1 -
|
||||
54 #1 WaveSurfer ( 777.7, 381.3) d= 240.1 g= 284.4 | #2 OscillatorB ( 593.1, 27.8) d= 113.0 g= 48.4 1 -
|
||||
55 #1 WaveSurfer ( 774.7, 376.1) d= 234.6 g= 304.4 | #2 OscillatorB ( 591.1, 32.4) d= 119.3 g= 68.4 1 -
|
||||
56 #1 WaveSurfer ( 770.6, 370.4) d= 229.9 g= 324.4 | #2 OscillatorB ( 588.2, 37.6) d= 124.8 g= 88.4 1 ScannedBotEvent(direction=124.79623116335074,energy=95.5,scannedBotId=2,scannedByBotId=1,speed=6.0,turnNumber=56,x=588.1570933782766,y=37.63272271510615)
|
||||
57 #1 WaveSurfer ( 765.5, 364.2) d= 233.9 g= 304.4 | #2 OscillatorB ( 584.2, 43.4) d= 125.6 g= 108.4 1 ScannedBotEvent(direction=233.88278297201384,energy=97.0,scannedBotId=1,scannedByBotId=2,speed=8.0,turnNumber=57,x=765.4578690475312,y=364.2401036157634)
|
||||
58 #1 WaveSurfer ( 760.7, 357.8) d= 229.9 g= 284.4 | #2 OscillatorB ( 580.1, 49.1) d= 125.7 g= 88.4 1 -
|
||||
59 #1 WaveSurfer ( 755.6, 351.7) d= 225.9 g= 264.4 | #2 OscillatorB ( 576.0, 54.8) d= 125.7 g= 68.4 1 -
|
||||
60 #1 WaveSurfer ( 750.0, 345.9) d= 221.9 g= 244.4 | #2 OscillatorB ( 571.9, 60.4) d= 125.7 g= 48.4 0 BulletHitWallEvent(bullet={'bulletId': 1, 'ownerId': 2, 'power': 2.0, 'x': 805.7098345126777, 'y': 369.19441014499444, 'direction': 44.124617464630376},turnNumber=60)
|
||||
61 #1 WaveSurfer ( 744.1, 340.6) d= 217.9 g= 224.4 | #2 OscillatorB ( 567.8, 66.1) d= 129.7 g= 28.4 0 -
|
||||
62 #1 WaveSurfer ( 737.7, 335.7) d= 213.9 g= 204.4 | #2 OscillatorB ( 563.4, 71.5) d= 133.7 g= 8.4 0 -
|
||||
63 #1 WaveSurfer ( 731.1, 331.2) d= 209.9 g= 184.4 | #2 OscillatorB ( 558.5, 76.6) d= 137.7 g= 348.4 0 -
|
||||
64 #1 WaveSurfer ( 724.2, 327.2) d= 205.9 g= 164.4 | #2 OscillatorB ( 553.4, 81.3) d= 141.7 g= 328.4 0 ScannedBotEvent(direction=205.88278297201384,energy=97.0,scannedBotId=1,scannedByBotId=2,speed=8.0,turnNumber=64,x=724.1704425002833,y=327.2174030657598) ScannedBotEvent(direction=141.66553082336077,energy=95.5,scannedBotId=2,scannedByBotId=1,speed=7.0,turnNumber=64,x=553.3631148218225,y=81.29696461004337)
|
||||
65 #1 WaveSurfer ( 717.0, 323.7) d= 201.9 g= 184.4 | #2 OscillatorB ( 547.9, 85.6) d= 145.7 g= 348.4 0 ScannedBotEvent(direction=201.88278297201384,energy=97.0,scannedBotId=1,scannedByBotId=2,speed=8.0,turnNumber=65,x=716.9729305436416,y=323.7251514090204)
|
||||
66 #1 WaveSurfer ( 709.5, 320.7) d= 197.9 g= 204.4 | #2 OscillatorB ( 542.1, 89.6) d= 149.7 g= 8.4 0 -
|
||||
67 #1 WaveSurfer ( 701.9, 318.3) d= 193.9 g= 224.4 | #2 OscillatorB ( 536.1, 93.1) d= 153.7 g= 28.4 0 -
|
||||
68 #1 WaveSurfer ( 694.2, 316.4) d= 189.9 g= 244.4 | #2 OscillatorB ( 529.8, 96.2) d= 157.7 g= 48.4 0 -
|
||||
69 #1 WaveSurfer ( 686.3, 315.0) d= 185.9 g= 264.4 | #2 OscillatorB ( 523.3, 98.9) d= 161.7 g= 68.4 0 -
|
||||
70 #1 WaveSurfer ( 678.3, 314.2) d= 181.9 g= 284.4 | #2 OscillatorB ( 516.7, 101.1) d= 165.7 g= 88.4 0 -
|
||||
71 #1 WaveSurfer ( 670.3, 313.9) d= 177.9 g= 304.4 | #2 OscillatorB ( 509.9, 102.8) d= 169.7 g= 108.4 0 -
|
||||
72 #1 WaveSurfer ( 662.3, 314.2) d= 173.9 g= 324.4 | #2 OscillatorB ( 503.0, 104.1) d= 173.7 g= 128.4 0 ScannedBotEvent(direction=173.88278297201384,energy=97.0,scannedBotId=1,scannedByBotId=2,speed=8.0,turnNumber=72,x=662.3401648296657,y=314.20712339102033) ScannedBotEvent(direction=173.66553082336077,energy=95.5,scannedBotId=2,scannedByBotId=1,speed=7.0,turnNumber=72,x=502.9887627211851,y=104.07835014332152)
|
||||
|
||||
## Full integrity verification output
|
||||
```
|
||||
== top-level types on the wire ==
|
||||
3230 TickEventForObserver
|
||||
3 RoundStartedEvent
|
||||
3 RoundEndedEventForObserver
|
||||
1 GameStartedEventForObserver
|
||||
1 GameEndedEventForObserver
|
||||
|
||||
== turnNumber continuity ==
|
||||
count=3230 min=1 max=1453 distinct=1453
|
||||
round 1: 751 turns [1..751] gaps=NONE dups=NONE
|
||||
round 2: 1026 turns [1..1026] gaps=NONE dups=NONE
|
||||
round 3: 1453 turns [1..1453] gaps=NONE dups=NONE
|
||||
VERDICT: CONTIGUOUS, no drops
|
||||
|
||||
== bots ==
|
||||
bot-id-set (1, 2) (WaveSurfer, OscillatorBot): 3230/3230 ticks
|
||||
bulletStates ownerId sets: {(): 2210, (2,): 654, (1,): 218, (1, 1): 86, (1, 2): 29, (2, 2): 33} (empty = no bullets in flight)
|
||||
|
||||
== events[] histogram (inner) ==
|
||||
945 ScannedBotEvent
|
||||
214 BotHitWallEvent
|
||||
52 BotHitBotEvent
|
||||
38 BulletFiredEvent
|
||||
29 BulletHitWallEvent
|
||||
7 BulletHitBotEvent
|
||||
3 BotDeathEvent
|
||||
OK BulletFiredEvent: 38
|
||||
OK BulletHitBotEvent: 7
|
||||
OK BulletHitWallEvent: 29
|
||||
MISS BulletHitBulletEvent: 0
|
||||
OK ScannedBotEvent: 945
|
||||
OK BotDeathEvent: 3
|
||||
```
|
||||
@@ -0,0 +1,101 @@
|
||||
package dev.robocode.tankroyale.common.recording;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* UNFILTERED shadow of the tank-royale GameRecorder.
|
||||
*
|
||||
* Byte-for-byte compatible with the real class (same package, same binary signatures) so
|
||||
* that simply putting `shadow-classes/` FIRST on the classpath in front of
|
||||
* robocode-tankroyale-runner.jar makes the JVM load THIS class instead of the jarred one.
|
||||
* tank-royale itself is NOT modified.
|
||||
*
|
||||
* The only behavioural difference: RECORDABLE_EVENT_TYPES accepts EVERY top-level message
|
||||
* type instead of the original 6. That is done with a Set whose contains() is always true,
|
||||
* so unknown/new event types are captured too -- completeness by construction.
|
||||
*
|
||||
* START/END_RECORDING_TYPES are unchanged: the recording window still opens on
|
||||
* GameStartedEventForObserver and closes on GameEnded/GameAborted.
|
||||
*/
|
||||
public final class GameRecorder implements AutoCloseable {
|
||||
|
||||
/** Kotlin companion object, mirrored so BattleRunner's bytecode links against us. */
|
||||
public static final Companion Companion = new Companion();
|
||||
|
||||
public static final class Companion {
|
||||
private Companion() {}
|
||||
|
||||
public final Set<String> getRECORDABLE_EVENT_TYPES() {
|
||||
return RECORDABLE_EVENT_TYPES;
|
||||
}
|
||||
|
||||
public final Set<String> getSTART_RECORDING_TYPES() {
|
||||
return START_RECORDING_TYPES;
|
||||
}
|
||||
|
||||
public final Set<String> getEND_RECORDING_TYPES() {
|
||||
return END_RECORDING_TYPES;
|
||||
}
|
||||
}
|
||||
|
||||
/** Kotlin synthetic accessors that BattleRunner's bytecode calls. */
|
||||
public static final Set<String> access$getRECORDABLE_EVENT_TYPES$cp() {
|
||||
return RECORDABLE_EVENT_TYPES;
|
||||
}
|
||||
|
||||
public static final Set<String> access$getSTART_RECORDING_TYPES$cp() {
|
||||
return START_RECORDING_TYPES;
|
||||
}
|
||||
|
||||
public static final Set<String> access$getEND_RECORDING_TYPES$cp() {
|
||||
return END_RECORDING_TYPES;
|
||||
}
|
||||
|
||||
/** Accept-all set: contains() is unconditionally true, so nothing on the wire is dropped. */
|
||||
private static final Set<String> RECORDABLE_EVENT_TYPES = new AbstractSet<String>() {
|
||||
@Override public boolean contains(Object o) { return true; }
|
||||
@Override public Iterator<String> iterator() { return Collections.<String>emptyIterator(); }
|
||||
@Override public int size() { return 0; }
|
||||
@Override public String toString() { return "[ALL TYPES]"; }
|
||||
};
|
||||
|
||||
private static final Set<String> START_RECORDING_TYPES = Collections.singleton("GameStartedEventForObserver");
|
||||
|
||||
private static final Set<String> END_RECORDING_TYPES = new java.util.HashSet<>(
|
||||
java.util.Arrays.asList("GameAbortedEvent", "GameEndedEventForObserver"));
|
||||
|
||||
public final File file;
|
||||
private final PrintWriter output;
|
||||
|
||||
public GameRecorder(String dir) {
|
||||
final String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss"));
|
||||
file = new File(dir, "game-" + now + ".battle.gz");
|
||||
// Kotlin has no checked exceptions; wrap so the binary signature matches the jarred class.
|
||||
try {
|
||||
output = new PrintWriter(new GZIPOutputStream(new FileOutputStream(file)));
|
||||
} catch (java.io.IOException e) {
|
||||
throw new java.io.UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public final void record(String jsonLine) {
|
||||
output.println(jsonLine);
|
||||
}
|
||||
|
||||
@Override public void close() {
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user