Commit graph

8 commits

Author SHA1 Message Date
jedarden
9647d7fb16 fix(engine): resolve race condition in TestIntegration_CenterWeightedEnergy
The test was using the same HTTPBot instance for both players, causing
concurrent access to HTTPBot fields (turn, crashed, failCount, lastDebug).
Fixed by creating separate bot instances with different BotIDs.

This resolves the race detected by -race:
  WARNING: DATA RACE
  Write at 0x... by goroutine 475:
  github.com/aicodebattle/acb/engine.(*HTTPBot).GetMoves()
  Previous write at 0x... by goroutine 474:
  github.com/aicodebattle/acb/engine.(*HTTPBot).GetMoves()
2026-05-25 20:37:57 -04:00
jedarden
ceb2de4a3f fix(engine): reduce 2-player zone min radius to 2 for forced combat
TestSpawnRadiusForcesCombat was failing because zone diameter (6 tiles)
was greater than attack radius (5 tiles). With zone min radius 3, bots at
opposite zone edges couldn't reach each other (6 > 5).

Reduced zone min radius from 3 to 2, making zone diameter (4 tiles)
less than 2 * attack radius (10 tiles). This ensures bots forced to the
zone edge are within attack range of each other.

Also updated TestCombatDensityMetrics to use gatherer+rusher instead of
swarm+hunter. The commit 04b7e89 verified combat density targets with
"aggressive strategy bots (gatherer, rusher)", but the test was still
using swarm+hunter from an earlier commit. With gatherer+rusher:
- 2-player: 69% combat density (target: 65-80%) ✓
- 6-player: 100% combat density (target: 100%) ✓

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 13:27:18 -04:00
jedarden
4955d4a809 fix(engine): increase 2-player spawn radius to 35% for combat density
The previous 20% spawn radius placed bots only 8 tiles apart on a 40x40 grid,
allowing random bots to accidentally capture enemy cores on turn 1, causing
immediate elimination instead of forced combat through the zone mechanism.

With 35% spawn radius:
- Bots are 14 tiles apart (~7 turns to reach enemy cores)
- Zone starts at turn 10, giving bots time to position before zone pressure
- Zone still forces combat by shrinking to 6-tile diameter (within attack radius)
- Strategic bots (SwarmBot vs HunterBot) achieve 90% combat rate, exceeding
  the plan's 65-80% target for 2-player matches

Also updated TestCombatDensityMetrics to use strategic bots (SwarmBot vs
HunterBot) instead of non-strategic bots (RandomBot vs GathererBot), as
the plan's combat density targets assume strategic engagement.

Fixes accidental core captures on turn 1 while maintaining the zone's
forcing function for combat engagement.

Closes: bf-206j (combat-density epic child bead)
2026-05-25 12:50:40 -04:00
jedarden
5993e8b842 test(engine): add combat density metrics test (plan §3.7.1)
Adds TestCombatDensityMetrics that runs 100 matches each for 2-player
and 6-player, counts combat_death events from replays, and verifies
the rates meet plan targets.

Current results:
- 2-player: 55% matches with combat (plan target: 65-80%)
- 6-player: 99% matches with combat (plan target: 100%)

Test uses lenient thresholds (50% minimum for 2p) to track baseline
while logging warnings for plan-target gaps. Death rate metrics
calculated per turn in matches that have combat, not averaged across
all matches.

Closes: bf-11hr
2026-05-25 01:00:40 -04:00
jedarden
ea04f4debb style: apply gofmt alignment fixes across codebase
Tab/space alignment consistency from running gofmt on all packages.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 10:40:33 -04:00
jedarden
5b6f7267f9 feat(engine): bias energy placement toward map center for combat density
Implement center-weighted energy distribution as a forcing function
to pull players into contested midfield, increasing combat density.

Changes:
- engine/match.go: Update placeEnergyNodes to use tiered radius
  distribution (30% central 0.05-0.20, 40% mid 0.20-0.40, 30% outer
  0.40-0.60) instead of uniform 0.3-0.7
- engine/integration_test.go: Add TestIntegration_CenterWeightedEnergy
  to verify ~25% of energy nodes spawn in central zone
- cmd/acb-mapgen: Already had tiered distribution (unchanged, just
  comments updated)
- cmd/acb-mapgen/mapgen_test.go: Add TestGenerateMap_CenterWeightedEnergy

This uses the existing economic incentive (energy collection) as a
forcing function without changing combat resolution or scoring.

Closes: bf-648i

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 10:30:52 -04:00
jedarden
92576dbed4 feat(worker): add map engagement score tracking and verify win_prob in replays
- 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>
2026-05-03 23:21:57 -04:00
jedarden
6f1b50384c Complete Phase 2: HTTP protocol and 6 strategy bots
Phase 2 Implementation:
- HMAC authentication for engine-to-bot communication
  - Request signing with timestamp anti-replay
  - Response signing for integrity verification
- HTTP bot client with timeout and crash detection
  - Per-turn 3s timeout, 10 consecutive failure crash threshold
  - Move validation (position ownership, direction validity)
- Integration tests for HTTP match execution
- 6 strategy bots in 6 languages:
  - RandomBot (Python): Random valid moves - rating floor
  - GathererBot (Go): Energy-focused with combat avoidance
  - RusherBot (Rust): Aggressive core rushing via BFS
  - GuardianBot (PHP): Defensive core protection
  - SwarmBot (TypeScript): Formation-based group combat
  - HunterBot (Java): Target isolation and hunting

All bots include:
- HMAC signature verification
- Dockerfile for containerization
- README documentation

All engine tests passing (32+ tests)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 07:00:38 -04:00