## Direct proof of the BotDeath drop mechanism in `robocode_tankroyale_botapi` ## 1.0.7, at the API level (no battle required). ## ## `event_queue.isCritical` contains only `ekDeath`, `ekWonRound` and ## `ekSkippedTurn` — NOT `ekBotDeath`. `removeOldEvents` deletes every ## non-critical event whose `turnNumber < currentTurn - MAX_EVENTS_AGE`. ## Therefore a `BotDeathEvent` for ANOTHER bot is silently dropped whenever the ## bot falls more than two turns behind, which is why `onBotDeath` cannot be the ## tracker's only death signal. ## ## Run: nim c -r common_libs/tests/test_event_drop_mechanism.nim import robocode_tankroyale_botapi var failures = 0 proc check(name: string, ok: bool) = if ok: echo "PASS: ", name else: echo "FAIL: ", name; inc failures const CurrentTurn = 8 proc botDeathAt(turn: int): BotEvent = BotEvent(kind: ekBotDeath, turnNumber: turn, botDeath: BotDeathEvent(turnNumber: turn, victimId: 2)) proc deathAt(turn: int): BotEvent = BotEvent(kind: ekDeath, turnNumber: turn, death: BotDeathEvent(turnNumber: turn, victimId: 1)) proc testBotDeathIsNotCritical() = let e = botDeathAt(5) check "ekBotDeath is not critical", not e.isCritical check "ekDeath IS critical", deathAt(5).isCritical proc testBotDeathDroppedWhenOlderThanMaxAge() = var eq = initEventQueue() eq.addEvent(botDeathAt(CurrentTurn - MAX_EVENTS_AGE - 1)) # age 3 eq.removeOldEvents(CurrentTurn) check "ekBotDeath older than MAX_EVENTS_AGE is dropped", eq.events.len == 0 proc testBotDeathKeptAtMaxAge() = var eq = initEventQueue() eq.addEvent(botDeathAt(CurrentTurn - MAX_EVENTS_AGE)) # age 2 eq.removeOldEvents(CurrentTurn) check "ekBotDeath at exactly MAX_EVENTS_AGE age is kept", eq.events.len == 1 proc testCriticalDeathSurvives() = var eq = initEventQueue() eq.addEvent(deathAt(CurrentTurn - MAX_EVENTS_AGE - 5)) eq.removeOldEvents(CurrentTurn) check "critical ekDeath survives any age", eq.events.len == 1 proc testScannedBotAlsoDropped() = # Every other non-critical event is dropped too, so a lagging bot also loses # scans/hits; BotDeath is the one with a permanent consequence. var eq = initEventQueue() eq.addEvent(BotEvent(kind: ekScannedBot, turnNumber: CurrentTurn - 3, scannedBot: ScannedBotEvent(`type`: "ScannedBotEvent", turnNumber: CurrentTurn - 3, scannedByBotId: 0, scannedBotId: 2, energy: 100.0, x: 0.0, y: 0.0, direction: 0.0, speed: 0.0))) eq.removeOldEvents(CurrentTurn) check "ekScannedBot older than MAX_EVENTS_AGE is dropped too", eq.events.len == 0 testBotDeathIsNotCritical() testBotDeathDroppedWhenOlderThanMaxAge() testBotDeathKeptAtMaxAge() testCriticalDeathSurvives() testScannedBotAlsoDropped() if failures > 0: echo "\n", failures, " check(s) FAILED" quit(1) echo "\nAll event-drop mechanism checks passed."