def execute_scans(players, subjects): # TODO: account for world wrapping for player in players: (radius,) = player.scan # TODO: subtract energy cost (and signal death if it proved fatal) for subject in subjects: # calculate distance to all subjects, signal detect if within scan distance = util.distance(player.location, subject.location) if distance <= radius: player.signal_detect( subject.name, util.angle(player.location, subject.location), distance, subject.energy )
def execute_scans(players, subjects): # TODO: account for world wrapping for player in players: (radius, ) = player.scan # TODO: subtract energy cost (and signal death if it proved fatal) for subject in subjects: # calculate distance to all subjects, signal detect if within scan distance = util.distance(player.location, subject.location) if distance <= radius: player.signal_detect( subject.name, util.angle(player.location, subject.location), distance, subject.energy)
def execute_fires(players, subjects): # TODO: account for world wrapping for player in players: # unpack required information (angle, distance, radius, charge) = player.fire loc_x, loc_y = player.location lim_x, lim_y = config.game.field_dimensions # calculate the epicenter of the blast epicenter = ((loc_x + cos(angle) * distance) % lim_x, (loc_y + sin(angle) * distance) % lim_y) # TODO: subtract energy cost (and signal death if it proved fatal) for subject in subjects: # calculate distance to epicenter for all subjects, signal hit if ... hit if util.distance(epicenter, subject.location) <= radius: subject.signal_hit(player.name, util.angle(subject.location, epicenter), charge)
def execute_scans(self, players): result_signals = [] for player in players: (radius, ) = player.scan_action logging.info('player {} at {} scanned with radius {}'.format( player.name, player.location, radius)) # subtract energy cost cost = game.scan_cost(radius) prev_energy = player.energy player.energy -= cost self.emit_event(type='player_scan', player=player.name, location=player.location, radius=radius, cost=cost, energy=(prev_energy, player.energy)) if player.energy <= 0.0: # signal player is dead result_signals.append(self.player_death(player)) self.emit_event(type='player_suicide', action='scan', cost=cost, energy=(prev_energy, player.energy)) logging.info('player {} died from exhaustion (scan)'.format( player.name)) else: x, y = player.location # calculate the bounding box for the scan bounds = (x - radius, y - radius, x + radius, y + radius) # collect all players in the bounding box for the blast subjects = set() for region in util.generate_wrapped_bounds( (0, 0, self.width, self.height), bounds): subjects = subjects.union(self.find_players(region)) radius = util.WrappedRadius(player.location, radius, (self.width, self.height)) # check if subject in scan radius (bounding box possibly selects too many players) for subject in subjects: # calculate distance to all subjects, signal detect if within scan # TODO: using radius twice runs the expensive operation twice (distance, wrapped_location) = radius.distance(subject.location) if subject is not player and subject.location in radius: result_signals.append( (player.signal_detect, subject.name, util.angle(player.location, wrapped_location), util.distance(player.location, wrapped_location), subject.energy)) self.emit_event(type='player_detect', player=player.name, energy=player.energy, location=player.location, radius=radius, detected=subject.name, detected_location=subject.location, detected_energy=subject.energy) logging.info('player {} detected {}'.format( player.name, subject.name)) return result_signals
def execute_scans(self, players): result_signals = [] for player in players: (radius,) = player.scan_action logging.info('player {} at {} scanned with radius {}'.format( player.name, player.location, radius )) # subtract energy cost cost = game.scan_cost(radius) prev_energy = player.energy player.energy -= cost self.emit_event( type = 'player_scan', player = player.name, location = player.location, radius = radius, cost = cost, energy = (prev_energy, player.energy) ) if player.energy <= 0.0: # signal player is dead result_signals.append(self.player_death(player)) self.emit_event( type = 'player_suicide', action = 'scan', cost = cost, energy = (prev_energy, player.energy) ) logging.info('player {} died from exhaustion (scan)'.format(player.name)) else: x, y = player.location # calculate the bounding box for the scan bounds = ( x - radius, y - radius, x + radius, y + radius ) # collect all players in the bounding box for the blast subjects = set() for region in util.generate_wrapped_bounds((0, 0, self.width, self.height), bounds): subjects = subjects.union(self.find_players(region)) radius = util.WrappedRadius(player.location, radius, (self.width, self.height)) # check if subject in scan radius (bounding box possibly selects too many players) for subject in subjects: # calculate distance to all subjects, signal detect if within scan # TODO: using radius twice runs the expensive operation twice (distance, wrapped_location) = radius.distance(subject.location) if subject is not player and subject.location in radius: result_signals.append((player.signal_detect, subject.name, util.angle(player.location, wrapped_location), util.distance(player.location, wrapped_location), subject.energy )) self.emit_event( type = 'player_detect', player = player.name, energy = player.energy, location = player.location, radius = radius, detected = subject.name, detected_location = subject.location, detected_energy = subject.energy ) logging.info('player {} detected {}'.format(player.name, subject.name)) return result_signals