Skip to content

Latest commit

 

History

History
194 lines (137 loc) · 7.84 KB

File metadata and controls

194 lines (137 loc) · 7.84 KB

MedBot Pathfinding System - Complete Overhaul

MAJOR ISSUES FIXED:

1. UNIFIED A* PATHFINDING SYSTEM

  • REMOVED broken HPA* implementation (as requested - "it sucks")
  • SIMPLIFIED to use only A* algorithm for all pathfinding:
    • Area-level A*: For pathfinding between major navigation areas
    • Fine-point A*: For detailed pathfinding within areas using fine points
  • RESULT: Consistent, predictable pathfinding using proven A* algorithm

2. FIXED INTER-AREA CONNECTIONS

  • PROBLEM: Inter-area connections weren't being processed properly
  • ROOT CAUSE: Areas missing required boundary data (minX, maxX, minY, maxY) and edgeSets
  • SOLUTION:
    • Fixed multi-tick setup to properly generate area bounds before connection processing
    • Added proper validation and regeneration of edgeSets if missing
    • Added comprehensive debugging to track connection generation
  • RESULT: Fine points between adjacent areas now connect properly

3. MEMORY LEAK FIXES

  • PROBLEM: Fine point caches growing indefinitely, causing memory bloat
  • SOLUTION:
    • Added G.CleanupMemory() function with smart cache management
    • Automatic cleanup every 30 seconds
    • Clears cached fine points when over 1000 areas cached
    • Force garbage collection when memory > 512MB
    • Clears unused hierarchical data when pathfinding disabled
  • RESULT: Memory usage now controlled and stable

4. REMOVED BROKEN ALGORITHMS

  • REMOVED: GBFS (Greedy Best-First Search) - inconsistent results
  • REMOVED: HPA* (Hierarchical Pathfinding A*) - overcomplicated and buggy
  • STANDARDIZED: All pathfinding now uses proven A* algorithm
  • RESULT: Consistent, predictable pathfinding behavior

5. PERFORMANCE OPTIMIZATIONS

  • Connection Processing: Now happens during setup time, not during gameplay
  • Background Processing: Multi-tick system prevents game freezing
  • Smart Caching: Fine points generated on-demand and cached intelligently
  • Efficient Data Structures: Proper neighbor lookups and cost management
  • RESULT: Smooth gameplay with no stuttering during pathfinding

6. OPTIMIZED STITCHING ALGORITHM

  • PROBLEM: Complex reservation-based stitching was slow and overcomplicated
  • SOLUTION:
    • Simple approach: Each edge node connects to its 2 closest neighbors
    • No reservation logic: Direct distance-based matching
    • Bidirectional connections: Ensures robust inter-area links
    • Duplicate prevention: Avoids redundant connections
    • Faster processing: Increased from 5 to 10 areas per tick
  • RESULT: Much faster setup time with better connection quality

SIMPLIFIED PATHFINDING FLOW:

Phase 1: Area-Level A*

  1. Find path between major navigation areas using A*
  2. Uses connection costs and penalties for realistic routing
  3. Handles blocked/expensive connections gracefully

Phase 2: Fine-Point A*

  1. For each area in the area-level path:
    • Find best entry/exit points using edge points
    • Use A* to navigate through fine points within the area
    • Connect areas smoothly using inter-area connections
  2. Results in smooth, detailed path using fine navigation points

Fallback: Simple A*

  • If hierarchical pathfinding fails or is disabled
  • Direct A* pathfinding on main navigation nodes
  • Still uses optimized connection costs

HEIGHT-BASED COST SYSTEM: ✅

Walking Modes (Selector in Menu)

  • Smooth Walking (18u steps): Conservative movement with height penalties

    • Only allows 18-unit steps without penalties
    • Adds 10 cost per 18 units of height difference
    • More reliable but slower pathfinding
  • Aggressive Walking (72u jumps): Allows duck-jumping without penalties

    • Permits 72-unit jumps without extra cost
    • Faster movement but may get stuck on complex geometry
    • Better for open areas

Cost Calculation Logic

  • Base cost = connection distance
  • Height penalty = floor(heightDiff / 18) * 10 (smooth mode only)
  • Accessibility penalties for difficult terrain (1.5x to 10x multipliers)
  • Automatic recalculation when walking mode changes

Commands

  • pf_costs recalc - Recalculate all costs for current walking mode
  • pf_costs info - Show walking mode and cost statistics

PATH OPTIMISER SYSTEM: ✅

Smart Skip Algorithm

Replaces the old node skipping system with an intelligent binary-search approach:

Key Features:

  • Only ONE expensive isWalkable trace per tick maximum
  • Windowed lookahead: Only checks 10 nodes or 600 units ahead by default
  • Binary search probing: O(log n) instead of O(n) performance
  • Failure caching: Remembers failed attempts for 12 ticks to prevent oscillation
  • Blast recovery: Auto-resyncs when knocked off path

Performance Benefits

  • Eliminates rubber-banding - no more oscillating between nodes
  • Massive FPS improvement - from potentially 100+ traces per tick to exactly 1
  • Smart for long paths - 1000-node paths are handled as efficiently as 10-node paths
  • Handles knockback gracefully - automatically recovers from explosions/airblast

Tunable Parameters (in Menu)

  • Lookahead Nodes (5-30): How many nodes ahead to consider for skipping
  • Lookahead Distance (300-1200): Maximum distance in units to check
  • Failure Cooldown (6-60): Ticks to wait before retrying failed skips

Recovery Systems

  1. Distance-based re-sync: If displaced <1200 units, tries to snap back to existing path
  2. Automatic repath: If completely off-path, triggers new pathfinding
  3. Failure penalties: Problematic connections get higher costs over time

Commands

  • pf_optimizer info - Show settings and cache status
  • pf_optimizer clear - Clear failure cache
  • pf_optimizer test - Test performance on current path

CODE QUALITY IMPROVEMENTS:

Better Error Handling

  • Proper null checks and fallbacks
  • Graceful degradation when data is missing
  • Comprehensive logging for debugging

Memory Management

  • Automatic cache cleanup
  • Smart memory monitoring
  • Prevents memory leaks and bloat

Modular Design

  • Clear separation between pathfinding algorithms
  • Reusable functions for area entry/exit point finding
  • Consistent API across all pathfinding methods

PERFORMANCE METRICS:

  • Memory Usage: Now stable, automatic cleanup prevents bloat
  • Frame Rate: No more stuttering during pathfinding setup
  • Path Quality: Much more accurate and smooth navigation
  • Connection Success: Inter-area connections now work properly
  • Failure Recovery: Better handling of blocked or invalid paths

TESTING RECOMMENDATIONS:

  1. Test Inter-Area Navigation: Bot should now smoothly navigate between different map areas
  2. Memory Monitoring: Watch memory usage - should stay stable over long play sessions
  3. Path Quality: Paths should be smoother and more natural-looking
  4. Performance: No stuttering during bot operation
  5. Hierarchical vs Simple: Test both modes to ensure fallback works

FILES MODIFIED:

  • MedBot/Navigation.lua - Main pathfinding logic completely rewritten
  • MedBot/Utils/A-Star.lua - Removed broken algorithms, added sub-node A*
  • MedBot/Modules/Node.lua - Fixed inter-area connection processing
  • MedBot/Utils/Globals.lua - Added memory management system
  • MedBot/Main.lua - Added memory cleanup calls

SUMMARY:

The pathfinding system has been completely overhauled to use only the A* algorithm for all pathfinding as requested. All mentions and usage of GBFS (Greedy Best-First Search) and other suboptimal algorithms have been removed. The broken HPA* has been eliminated, inter-area connections are now working, memory leaks are fixed, and the system uses consistent A* pathfinding throughout. The bot should now navigate optimally and reliably without algorithm confusion or suboptimal path choices.