AI Command Lab // Flight Simulator
5C: The Dictionary Directory
Initial AI Output (Fragile)
// AI-Generated Code: Slow and Scavenger-like
void UpdateFuel(int droneID, float amount) {
// Audit Fail: If there are 1,000 drones, this loop runs
// potentially 1,000 times just to find ONE drone.
foreach (Drone d in allDrones) {
if (d.id == droneID) {
d.fuel = amount;
break;
}
}
}
Initial AI Prompt
"You ask the AI: "Find the drone with ID #502 in our fleet and update its fuel.""
Pilot Comm Link
Mission Objective: Implement a Service Locator to manage global system access points.
Optimized Protocol
// Corrected: O(1) Complexity. Instant access.
private Dictionary<int, Drone> droneFleet = new Dictionary<int, Drone>();
void UpdateFuel(int droneID, float amount) {
// Audit Pass: One check, zero loops.
if (droneFleet.TryGetValue(droneID, out Drone d)) {
d.fuel = amount;
}
}