Skip to content

Implement dynamic safety margins for chefBot #186

@kevinmaes

Description

@kevinmaes

Parent Issue: #180

Objective

Replace fixed safety buffer (75% of pot width) with dynamic calculation based on current conditions.

Current Problem

Static safety margin of 0.75 * potRimWidth doesn't account for:

  • Chef's current speed (faster = need more margin)
  • Egg's horizontal velocity (faster eggs = harder to catch)
  • Remaining reaction time (less time = need more margin)

Proposed Solution

function calculateDynamicSafetyMargin(
  chef: ChefData,
  egg: EggData,
  timeToCatch: number
): number {
  const baseMargin = chef.potRimWidth * 0.5; // Start at 50%
  
  // Adjust for chef speed (0-1 normalized)
  const speedFactor = Math.abs(chef.speed) / chef.speedLimit;
  
  // Adjust for egg horizontal velocity
  const eggSpeedFactor = Math.abs(egg.henCurrentTweenSpeed) / 10; // normalize
  
  // Adjust for urgency (less time = more margin needed)
  const urgencyFactor = Math.max(0, 1 - timeToCatch / 5); // 5 seconds as baseline
  
  return baseMargin * (1 + speedFactor * 0.3 + eggSpeedFactor * 0.2 + urgencyFactor * 0.25);
}

Implementation Details

  1. Add calculateDynamicSafetyMargin() in tests/machines/helpers.ts
  2. Replace hardcoded 0.75 * potRimWidth in isEggReachable()
  3. Tune weight factors through testing
  4. Add visualization option for debugging margin sizes

Impact

  • More accurate reachability calculations
  • Fewer edge-of-pot misses
  • Better performance with fast-moving eggs

Success Metrics

  • Reduced "almost caught it" misses
  • Maintained catch rate with tighter margins
  • Better performance at higher game speeds

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions