AI Command Lab // Flight Simulator
8E: The Cargo Shift
Initial AI Output (Fragile)
foreach (Enemy e in enemies) {
if (e.isDead) {
// FRAGILE CODE
// This throws an error immediately.
enemies.Remove(e);
}
}
Initial AI Prompt
"Ask the AI to remove dead enemies from the list."
Pilot Comm Link
Mission Objective: A skilled Mechanic directs the AI to use a reverse For loop.
Optimized Protocol
// AUDIT PASS: Iterate backwards to remove safely.
for (int i = enemies.Count - 1; i >= 0; i--) {
if (enemies[i].isDead) {
enemies.RemoveAt(i);
}
}