🐝 Spiral Search Algorithm
Optimized block searching for Minecraft bee AI - MoreBees Plugin
❌ Original Method (Full Cube)
Performance Stats:
Blocks scanned: 0
Time complexity: O(r³)
Search pattern: Sequential
Early termination: No
✅ Optimized Method (Spiral)
Performance Stats:
Blocks scanned: 0
Time complexity: O(r²) average
Search pattern: Radius-based spiral
Early termination: Yes
🧠 How the Spiral Algorithm Works
Step 1: Start searching at radius 1 (8 blocks around the bee)
Step 2: If no target found, expand to radius 2 (next 16 blocks)
Step 3: Continue expanding radius by radius until a target is found
Key Advantage: Stop immediately when first target is found (guaranteed to be closest!)
// Java Implementation Example
private Block findNearestTargetBlock() {
Location beeLoc = bee.getLocation();
int searchRadius = beeType.getSearchRadius();
// Spiral search - start from closest blocks
for (int radius = 1; radius <= searchRadius; radius++) {
Block found = searchAtRadius(beeLoc, radius);
if (found != null) {
return found; // Return immediately - closest found!
}
}
return null;
}