Fixed infinite loop in AI.