def is_too_close_to_empire_home_systems(system, home_systems): """ Checks if a system is too close to the player home systems. Player home systems should be at least 2 jumps away. """ for home_system in home_systems: if fo.jump_distance(system, home_system) < 2: return True return False
def find_systems_with_min_jumps_between(num_systems, systems_pool, min_jumps): """ Find requested number of systems out of a pool that are at least a specified number of jumps apart. """ # make several tries to get the requested number of systems attempts = min(100, len(systems_pool)) while attempts > 0: attempts -= 1 # shuffle our pool of systems so each try the candidates are tried in different order # (otherwise each try would yield the same result, which would make trying several times kind of pointless...) random.shuffle(systems_pool) # try to find systems that meet our condition until we either have the requested number # or we have tried all systems in our pool accepted = [] for candidate in systems_pool: # check if our candidate is at least min_jumps away from all other systems we already found if all(fo.jump_distance(candidate, system) >= min_jumps for system in accepted): # if yes, add the candidate to the list of accepted systems accepted.append(candidate) # if we have the requested number of systems, we can stop and return the systems we found if len(accepted) >= num_systems: return accepted # all tries failed, return an empty list to indicate failure return []