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 <noreply@anthropic.com>
This commit is contained in:
parent
d0df7f2fab
commit
390ebba52a
3 changed files with 15 additions and 9 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,12 +48,14 @@ impl RusherStrategy {
|
|||
let mut assigned_targets: HashSet<Position> = 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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue