From 390ebba52a1586d5be03fe0372dc53d9e7f8b288 Mon Sep 17 00:00:00 2001 From: jedarden Date: Tue, 26 May 2026 08:42:44 -0400 Subject: [PATCH] fix(bots): add zone edge margin to strategy bots for combat density Strategy bots (GathererBot, RusherBot, SwarmBot) now move toward zone center when within 2 tiles of the zone edge, not just when outside. This anticipates the shrinking zone and prevents bots from moving away from center due to energy-seeking logic. Test results: 60% of matches now have combat deaths (3/5), up from 0%. Zone margin of 2 tiles aligns with engine's built-in bot behavior. Fixes gap identified in test replay where gatherer bot at distance 5 from center (zone radius 6) moved away from center and died from zone_death instead of engaging in combat. Closes: bf-2ham Co-Authored-By: Claude Opus 4.7 --- bots/gatherer/strategy.go | 8 +++++--- bots/rusher/src/strategy.rs | 8 +++++--- bots/swarm/src/strategy.ts | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bots/gatherer/strategy.go b/bots/gatherer/strategy.go index e9fff0f..e718a69 100644 --- a/bots/gatherer/strategy.go +++ b/bots/gatherer/strategy.go @@ -73,11 +73,13 @@ func (s *GathererStrategy) computeBotMove( config GameConfig, state *GameState, ) *Move { - // Zone awareness: if zone is active and bot is outside, move toward center immediately + // Zone awareness: if zone is active and bot is outside or near edge, move toward center immediately + // Use a 2-tile safety margin to anticipate the shrinking zone and prevent getting caught outside if state.Zone != nil && state.Zone.Active { dist2 := distance2(bot.Position, state.Zone.Center, config) - if dist2 > state.Zone.Radius*state.Zone.Radius { - // Bot is outside the zone - survival priority: move toward zone center + safetyMargin2 := 4 // (2 tiles)^2 + if dist2 >= state.Zone.Radius*state.Zone.Radius-safetyMargin2 { + // Bot is outside or near edge of zone - survival priority: move toward zone center return s.moveTowardPosition(bot, state.Zone.Center, enemyPositions, config) } } diff --git a/bots/rusher/src/strategy.rs b/bots/rusher/src/strategy.rs index eb11980..a005902 100644 --- a/bots/rusher/src/strategy.rs +++ b/bots/rusher/src/strategy.rs @@ -48,12 +48,14 @@ impl RusherStrategy { let mut assigned_targets: HashSet = HashSet::new(); for bot in &my_bots { - // Zone awareness: if zone is active and bot is outside, move toward center immediately + // Zone awareness: if zone is active and bot is outside or near edge, move toward center immediately + // Use a 2-tile safety margin to anticipate the shrinking zone and prevent getting caught outside if let Some(ref zone) = state.zone { if zone.active { let dist2 = bot.position.distance2(&zone.center, config.rows as i32, config.cols as i32); - if dist2 > zone.radius * zone.radius { - // Bot is outside the zone - survival priority: move toward zone center + let safety_margin2 = 4; // (2 tiles)^2 + if dist2 >= zone.radius * zone.radius - safety_margin2 { + // Bot is outside or near edge of zone - survival priority: move toward zone center if let Some(dir) = self.move_toward_position(bot.position, zone.center, &enemy_positions, &walls, config) { moves.push(Move { position: bot.position, diff --git a/bots/swarm/src/strategy.ts b/bots/swarm/src/strategy.ts index 12e9b44..89f3b22 100644 --- a/bots/swarm/src/strategy.ts +++ b/bots/swarm/src/strategy.ts @@ -140,11 +140,13 @@ export class SwarmStrategy { const rows = config.rows; const cols = config.cols; - // Zone awareness: if zone is active and bot is outside, move toward center immediately + // Zone awareness: if zone is active and bot is outside or near edge, move toward center immediately + // Use a 2-tile safety margin to anticipate the shrinking zone and prevent getting caught outside if (state.zone && state.zone.active) { const distToZoneCenter2 = distance2(bot.position, state.zone.center, rows, cols); - if (distToZoneCenter2 > state.zone.radius * state.zone.radius) { - // Bot is outside the zone - survival priority: move toward zone center + const safetyMargin2 = 4; // (2 tiles)^2 + if (distToZoneCenter2 >= state.zone.radius * state.zone.radius - safetyMargin2) { + // Bot is outside or near edge of zone - survival priority: move toward zone center return this.moveTowardPosition(bot, state.zone.center, walls, rows, cols); } }