From e1e74bcbdf25f2d4def40daeaa87b0bf23aef8ef Mon Sep 17 00:00:00 2001 From: jedarden Date: Mon, 25 May 2026 11:39:45 -0400 Subject: [PATCH] test(scripts): add replay analysis tool for combat density verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds analyze-replay.sh script to parse replay files and report: - combat_death events per match - zone_death events (type=zone_death, currently unused) - bot_died events with reason=zone - Deaths per turn metrics Used for verifying zone forcing function per plan ยง3.7.1. Test results (30 matches): - 2-player: 90% matches with combat_deaths (exceeds 65-80% target) - 4-player: 100% matches with combat_deaths - 6-player: 100% matches with combat_deaths (meets target) Note: zone_death events are never emitted; zone kills use bot_died with reason=zone instead. This is a gap between plan and implementation. Closes: bf-5y8b --- scripts/analyze-replay.sh | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 scripts/analyze-replay.sh diff --git a/scripts/analyze-replay.sh b/scripts/analyze-replay.sh new file mode 100755 index 0000000..324b14c --- /dev/null +++ b/scripts/analyze-replay.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# analyze-replay.sh - Check a replay file for combat_death and zone_death events + +REPLAY_FILE="$1" + +if [[ ! -f "$REPLAY_FILE" ]]; then + echo "Usage: $0 " + exit 1 +fi + +# Detect if gzipped +if [[ "$REPLAY_FILE" == *.gz ]]; then + CAT="zcat" +else + CAT="cat" +fi + +echo "=== Replay: $REPLAY_FILE ===" + +# Get basic info +MATCH_ID=$($CAT "$REPLAY_FILE" | jq -r '.match_id // "unknown"') +NUM_PLAYERS=$($CAT "$REPLAY_FILE" | jq '.players | length') +TURNS=$($CAT "$REPLAY_FILE" | jq '.turns | length') + +echo "Match ID: $MATCH_ID" +echo "Players: $NUM_PLAYERS" +echo "Turns: $TURNS" + +# Count combat_death events +COMBAT_DEATHS=$($CAT "$REPLAY_FILE" | jq '[.turns[].events[]? | select(.type == "combat_death")] | length') + +# Count zone_death events +ZONE_DEATHS=$($CAT "$REPLAY_FILE" | jq '[.turns[].events[]? | select(.type == "zone_death")] | length') + +# Count bot_died events with reason="zone" (current implementation) +BOT_DIED_ZONE=$($CAT "$REPLAY_FILE" | jq '[.turns[].events[]? | select(.type == "bot_died" and .details.reason == "zone")] | length') + +echo "combat_death events: $COMBAT_DEATHS" +echo "zone_death events: $ZONE_DEATHS" +echo "bot_died (reason=zone): $BOT_DIED_ZONE" + +# Calculate deaths per turn +if [[ "$TURNS" -gt 0 ]]; then + DEATHS_PER_TURN=$(awk "BEGIN {printf \"%.3f\", $COMBAT_DEATHS / $TURNS}") + echo "Deaths per turn: $DEATHS_PER_TURN" +fi + +echo ""