def getClusterInteractions( self, clusters: List[DiscretePlayer] ) -> List[List[Tuple[DiscretePlayer, float]]]: interactions: List[List[Tuple[DiscretePlayer, float]]] = [] if len(clusters) <= 1: return interactions clusterCollisionDetector = KDTree( np.array([c.singuitiesMeanPosition for c in clusters])) interactingClusters = set() for cluster in clusters: if cluster in interactingClusters: continue [closest, secondClosest] = clusterCollisionDetector.query( cluster.singuitiesMeanPosition.reshape(1, 2), 2, return_distance=False)[0] if clusters[closest].id != cluster.id: closestCluster = clusters[closest] else: closestCluster = clusters[secondClosest] isColliding, distance2 = PhysicsEstimator.areSinguitiesColliding( clusters[secondClosest].singuitiesMeanPosition, cluster.singuitiesMeanPosition, clusters[secondClosest].singuitiesStd + cluster.singuitiesStd, returnDistance=True) if isColliding and closestCluster.id not in interactingClusters: interactingClusters.update([cluster.id, closestCluster.id]) interactions.append([(cluster, distance2), (closestCluster, distance2)]) return interactions
def getSpawnerInteractions( self, spawners: List[DiscreteSpawner], clusters: List[DiscretePlayer] ) -> Tuple[Dict[str, List[Tuple[DiscretePlayer, float]]], Dict[str, str]]: spawnerInteractions: Dict[str, List[Tuple[DiscretePlayer, float]]] = {} spawnerInteractedClusters: Dict[str, str] = {} def addSpawnerInteraction(spawner: DiscreteSpawner, cluster: DiscretePlayer, addedDistance2: float): spawnerInteractedClusters[cluster.id] = spawner.id if spawner.id in spawnerInteractions: spawnerInteractions[spawner.id].append( (cluster, addedDistance2)) else: spawnerInteractions[spawner.id] = [(cluster, addedDistance2)] clusterPositions = np.array( [cluster.singuitiesMeanPosition for cluster in clusters]) closestSpawnerIndices = DiscreteGameState.spawnerCollisionDetector.query( clusterPositions, return_distance=False).reshape(-1) for cluster, closestSpawnerIndex in zip(clusters, closestSpawnerIndices): closestSpawner = spawners[closestSpawnerIndex] isColliding, distance2 = PhysicsEstimator.areSinguitiesColliding( cluster.singuitiesMeanPosition, closestSpawner.position, cluster.singuitiesStd, returnDistance=True) if isColliding: addSpawnerInteraction(closestSpawner, cluster, distance2) return spawnerInteractions, spawnerInteractedClusters