- Add engine.CalculateMapEngagement() to compute map engagement scores from replay data (win_prob_crossings, critical_moments, map_coverage_pct, closeness, turn_pct)
- Add DBClient.UpdateMapEngagement() to update map engagement using rolling average
- Worker now calculates and writes map engagement scores after each match
- Add test to verify win_prob array is non-empty in produced replays
This implements the win probability Monte Carlo array storage in replay JSON
feature. The engine already called ComputeWinProbability() in MatchRunner.Run(),
so this commit adds the missing map engagement tracking.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Bot responses send direction as a string ("N","E","S","W") but the
engine Direction type is int with no custom JSON handling. json.Unmarshal
was failing silently, leaving Direction=0 (DirNone) for every move —
bots never moved and every match ended in stalemate.
MarshalJSON serializes as string; UnmarshalJSON accepts both forms.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The old test used "0"+sig[1:] to corrupt the signature. If the real HMAC
starts with "0", the corruption is a no-op and the test fails non-deterministically.
Replace with a fixed 64-char hex constant that is never a valid HMAC output.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two root causes prevented bots from making any moves:
1. SignRequest signing string included timestamp ({match_id}.{turn}.{timestamp}.{hash})
but all bots implement verifySignature without timestamp ({match_id}.{turn}.{hash}).
Fixed by dropping timestamp from the signing string; X-ACB-Timestamp header is still
sent for clock-skew checks but not in the HMAC.
2. The API stores bot secrets AES-GCM encrypted (184 hex chars) in the DB. The worker
was passing the ciphertext directly as the HMAC key, while bots use their plaintext
k8s secret (64 hex chars). Fixed by decrypting in the worker using ACB_ENCRYPTION_KEY.
Also tightens the home page winner filter to exclude winner_id="0" stalemates.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The partitionBots() return type was changed to a struct but two call
sites still referenced config.Turn inside bestExploreDir (now a
parameter), and RaiderBot had an unused enemySet variable.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add data/meta/rivalries.json to R2 upload list in uploadMetaJSONToR2
- Add attachCommunityHints() to narrative.go to enrich story arcs with
highest-upvote community tactical hints (upvotes >= 3, idea/mistake types)
- Fix detectRivalryArcs() key separator from "-" to "|" to avoid UUID
hyphen collisions when parsing bot ID pairs
- Fix partitionBots() call sites in bot_strategies_phase13.go to use
struct field access (.friendly, .enemy) matching updated return type
generator.go already contains generateArchetypes, generateCommunityHints,
and generateMatchFeedback (all called from generateAllIndexes). main.go
uploads all four outputs to R2 on every build cycle.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add transcript panel with turn-by-turn summaries generated from replay events
- Each turn shows: player moves, combat, deaths, captures, energy collection, spawns, win probability
- Add 'T' key shortcut to toggle transcript panel
- Panel supports three view modes: All Turns, ±10 Turns from Current, Recent 20 Turns
- Click on transcript entry to jump to that turn
- Current turn is highlighted in transcript with smooth scroll
- Panel content is selectable/copyable for screen reader users
- Transcript generation logic already existed in replay-viewer.ts; this adds the UI
- Transcript button slides in from right side of screen
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- SeasonID and RulesVersion already present in engine/types.go Config struct
- Worker already populates from active season row via DB join
- Config embedded in VisibleState sent to bots each turn (including turn 0)
- All starter kits (go, python, rust, java, csharp) already expose and log fields
- Add season_id/rules_version logging to JavaScript starter on turn 0
- TypeScript Config interface already includes season_id and rules_version
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add MapID field to engine Config struct for inclusion in replay JSON
- Add map_id to TypeScript Config interface
- Add map voting panel to replay viewer sidebar with:
- Map metadata display (dimensions, wall density, energy node count)
- Thumbs up/down vote buttons wired to POST /api/vote/map
- One vote per visitor enforcement (disables after voting)
- Net vote count display with positive/negative coloring
- Graceful fallback when map_id unavailable (local replays)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implementation complete:
1. engine/thumbnail.go - New thumbnail rendering package
- GenerateMatchThumbnail() creates 640x360 PNG thumbnails
- Renders grid, bots, cores, walls, energy with player colors
- SelectThumbnailTurn() chooses most interesting turn
- Pure Go stdlib image rendering (no canvas required)
2. cmd/acb-worker - Upload thumbnails to B2 alongside replays
- uploadThumbnail() generates PNG and uploads to B2
- Key: thumbnails/{match_id}.png, content-type: image/png
- Called after match completion, non-blocking on failure
3. cmd/acb-index-builder/deploy.go - Promote thumbnails to R2
- promoteRecentReplays() copies both replays AND thumbnails from B2 to R2
- Thumbnails promoted to warm cache alongside replay promotion
4. cmd/acb-index-builder/generator.go - Populate thumbnail URLs
- buildPlaylistMatch() now includes thumbnail_url field
- URL pattern: https://r2.aicodebattle.com/thumbnails/{match_id}.png
- Enables playlist cards and embed OG tags to show preview images
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replace random 2-player pairing with the full §6.1 algorithm:
- Seed selection: bot with oldest last-match timestamp (tiebreak: lowest bot ID)
- Format selection: seed's least-played player count among {2, 3, 4, 6}
- Opponent selection: Pareto 80%/16-rank skill proximity + oldest last-pairing
with seed + fewest 24h games for game-count balance
- Map selection: least-recently-used active map for the chosen player count,
with map_scores.last_used_at updated after each match
- Random player slot assignment for all participant counts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add crash_strikes and cooldown_until columns to bots table. Worker
increments strikes on crash (cooldown at 3), resets on success.
Matchmaker excludes cooldown bots from pairing, series scheduling,
and championship brackets. Fix erroneous cooldown filter on series
table in finalizeCompletedSeries (column only exists on bots).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The TestSpawnPriority_LowerIDBreaksTie test declared core1 but never
referenced it, causing a compile error. Added an assertion that
core1.LastSpawnedTurn remains 0 (confirming it didn't spawn).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Remove the lenient fallback that accepted bot responses missing the
X-ACB-Signature header. Missing or invalid signatures now cause the
response to be discarded and count toward the crash threshold (§4.5).
Add tests for missing-header, bad-signature, and crash-after-10 cases.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Collect GameState snapshots during match execution (one per turn), then
run 100 random-play rollouts per snapshot post-match to compute per-turn
win probabilities and detect critical moments (|delta| > 0.15). Results
are stored in the replay JSON as win_prob and critical_moments fields.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add Go implementations of 5 strategy bots directly into the engine:
- GathererBot: prioritizes energy collection, avoids combat
- RusherBot: aggressively rushes enemy cores
- GuardianBot: defends cores with cautious expansion
- SwarmBot: formation-based coordinated movement
- HunterBot: targets isolated enemy units
Update acb-local with bot selection flags:
- -bot0/-bot1: select bot strategies
- -list-bots: list available strategies
- Default to gatherer vs rusher for interesting gameplay
Enables demo replays with real strategic behavior without K8s infrastructure.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace broken Taylor series sin/cos approximations with math.Sin/math.Cos
in both engine/match.go and cmd/acb-mapgen. The Taylor series produced
incorrect results for angles > π, causing wrong positions in 3+ player maps.
Upgrade map generator wall placement from random scatter to cellular
automata (B5/S4 rule, 4 iterations) with rotational symmetry enforcement
and connectivity validation. Add comprehensive mapgen tests and dominance
win condition tests.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add connectivity.go: BFS-based map connectivity validation with retry
- Update mapgen to use connectivity checking by default
- Add determinism_test.go: property-based tests for reproducibility
- Same seed produces identical replays
- Turn execution is deterministic
- Grid operations are deterministic
- Combat resolution is deterministic
- Full 500-turn match validation
- All 32 tests pass
- Update PROGRESS.md: Phase 1 complete
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add engine package with toroidal grid, game state, turn execution
- Implement focus-fire combat resolution with simultaneous deaths
- Add fog of war visibility filtering for bot state
- Implement energy collection (contested resources denied)
- Add bot spawning at active cores
- Implement win conditions: elimination, draw, dominance, turns
- Add replay JSON writer for match recording
- Add match runner with concurrent bot communication
- Add CLI tools: acb-local (match runner), acb-mapgen (map generator)
- Add comprehensive unit tests (26 tests passing)
Exit criteria met: can run complete 500-turn matches and produce valid replays
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>