private static bool IsConnected(RobotAgent sourceRobot, RobotAgent targetRobot, HashSet <RobotAgent> seenRobots) { if (sourceRobot == targetRobot) { return(true); } if (!seenRobots.Add(sourceRobot)) { return(false); } #if ENABLE_F2 // F2: routes are assumed to be unidirectional, while they are in fact bidirectional. // Since this is reflected by incorrect assignments to agents' Inputs and Outputs, // the oracle must be fixed to account for this. var neighbouringRobots = sourceRobot.Outputs.Concat(sourceRobot.Inputs) .SelectMany(cart => cart.Outputs.Concat(cart.Inputs)); #else var neighbouringRobots = sourceRobot.Outputs.SelectMany(cart => cart.Outputs); #endif foreach (var neighbouringRobot in neighbouringRobots) { if (neighbouringRobot == targetRobot) { return(true); } if (IsConnected((RobotAgent)neighbouringRobot, targetRobot, seenRobots)) { return(true); } } return(false); }
private static bool IsConnected(RobotAgent source, RobotAgent target, HashSet<RobotAgent> seenRobots) { if (source == target) return true; if (!seenRobots.Add(source)) return false; foreach (var output in source.Outputs) { foreach (var output2 in output.Outputs) { if (output2 == target) return true; if (IsConnected((RobotAgent)output2, target, seenRobots)) return true; } } return false; }