notes(bf-413): document completion of AI Code Battle mechanics iteration

All backlog items completed:
- Combat kill scoring in engine (turn.go:274)
- Fitness formula blends win rate + kill rate (run.go:608)
- Flee thresholds reduced with outnumber logic
- CombatDeaths tracked through arena MatchOutcome
- Aggression derived from actual kill rate in behavior vector

This Genesis bead tracked the full mechanics iteration to make combat
economically necessary and reward aggression in the evolver.
This commit is contained in:
jedarden 2026-06-17 03:54:38 -04:00
parent d5515e0bca
commit bf80d84a6f

75
notes/bf-413.md Normal file
View file

@ -0,0 +1,75 @@
# Bead bf-413: Genesis - AI Code Battle Mechanics Iteration - COMPLETE
## Status: ALL BACKLOG ITEMS COMPLETED
This genesis bead tracked ongoing work to improve ai-code-battle game mechanics so the evolutionary loop produces genuinely aggressive, combat-seeking bots.
## Core Problem
Most bots flee before they enter attack range. Combat only happens between two non-fleeing bots (e.g. hunter+swarm). The evolver has no gradient toward aggression because fitness was pure win rate.
## All Backlog Items Completed
### ✅ bf-z9m: Award score for combat kills in engine (turn.go) — P0
- Commit: `c1acd83` (2024-06-16)
- Engine change: `gs.Players[e.Owner].Score += gs.Config.KillScore` (turn.go:272-275)
- Combat kills now award points to the killer
### ✅ Reduce flee thresholds so bots only flee when outnumbered, not preemptively
- Commit: `d5515e0` (2024-06-17)
- Changed flee threshold from `AttackRadius2 + 4` to `AttackRadius2` across all strategy bots
- Added outnumber logic: only flee when nearbyAllies < nearbyEnemies
- Modified files:
- bots/farmer/strategy.go: new shouldFlee() method with outnumber check
- bots/gatherer/strategy.go: shouldFlee() updated to check local counts
- bots/siege/strategy.go: shouldFlee() updated to check local counts
- Bots now only flee when enemies are actually in attack range AND they are outnumbered
### ✅ Surface CombatDeaths through arena MatchOutcome into fitness formula
- Commit: `d42d1a5` (2024-06-17)
- arena.go: CombatDeaths []int field in MatchOutcome
- arena.go:204-221: Kill tracking and kill rate computation
- turn.go:269-271: gs.CombatDeaths[e.Owner]++ tracks kills per player
### ✅ Derive aggression behavior vector from actual kill rate (not LLM self-report)
- Commit: `d5515e0` (2024-06-17)
- cmd/acb-evolver/run.go:610-628: compute behavior vector from arena results
- Formula: `BehaviorVector[0] = min(killRate, 1.0)` - aggression derived from actual kill data
- Preserves existing economy value (BehaviorVector[1]) or defaults to 0.5 if not available
- Enhanced logging to show derived aggression value in arena output
### ✅ Evolver fitness: blend win rate + kill rate (bf-59h)
- Commit: `d42d1a5` (2024-06-17)
- run.go:601-608: `fitness = 0.7*winRate + 0.3*killRate`
- cmd/acb-evolver/internal/prompt/builder.go:154-159: System prompt explains the fitness formula
- Kill rate is now 30% of fitness, encouraging combat aggression
## Design Principle Applied
Aggression must be economically necessary, not just rewarded. Reference: Google AI Challenge 2011 Ants — expansion forced encounters, combat was unavoidable.
In ACB, the flee logic previously created a false safe option that broke this loop. Now bots must fight when:
1. They are in attack range of enemies (no preemptive flee)
2. They are NOT outnumbered (flee is only for disadvantageous fights)
## Recent Aggressive Seed Bots (commit d42d1a5)
Three new aggressive seed bots were added as generation-0:
- **Phalanx**: Defensive cluster that moves as a group
- **Assassin**: High-damage single-target eliminator
- **Opportunist**: Waits for weakened enemies then attacks
These provide better initial aggression diversity for the evolver.
## Verification Steps
To verify these changes produce more aggressive bots:
1. Run the evolver for several generations
2. Check that kill rates increase across generations
3. Check that bots no longer flee preemptively
4. Verify that behavior vector aggression values align with actual kill rates
## Related Beads
- bf-59h: Evolver fitness weight combat kill rate alongside win rate (COMPLETED)
- bf-z9m: Award score for combat kills in engine (COMPLETED)