def step(self, units): """Performs a time step for this missile Moves towards target and damages if collision occurs If target is dead, this missile expires Parameters: units.enemies (UnitManager): The unit manager to select targets from Return: (persist, new_obstacles) pair, where: - persist (bool): True if the obstacle should persist in the game (else will be removed) - new_obstacles (list[AbstractObstacle]): A list of new obstacles to add to the game, or None """ if self.target.is_dead(): return False, None # move toward the target radius = euclidean_distance(self.position, self.target.position) if radius <= self.speed: self.target.damage(self.damage, 'explosive') return False, None # Rotate toward target and move angle = angle_between(self.position, self.target.position) self.rotation = rotate_toward(self.rotation, angle, self.rotation_threshold) dx, dy = polar_to_rectangular(self.speed, self.rotation) x, y = self.position self.position = x + dx, y + dy return True, None
def step(self, units): """Rotates toward 'target' and fires missile if possible""" self.cool_down.step() target = self._get_target(units.enemies) if target is None: return None # Rotate toward target angle = angle_between(self.position, target.position) partial_angle = rotate_toward(self.rotation, angle, self.rotation_threshold) self.rotation = partial_angle if angle != partial_angle or not self.cool_down.is_done(): return None self.cool_down.start() # Spawn missile on tower missile = Missile(self.position, self.cell_size, target, rotation=self.rotation, damage=self.get_damage(), grid_speed=.3) # Move missile to outer edge of tower radius = self.grid_size[0] / 2 delta = polar_to_rectangular(self.cell_size * radius, partial_angle) missile.move_by(delta) return [missile]
def step(self, data): """Rotates toward 'target' and attacks if possible""" self.cool_down.step() target = self.get_unit_in_range(data.enemies) if target is None: return # check if the enemy is custom enemy. for enemy in self.get_units_in_range(data.enemies): if not enemy.name == "Energy Enemy": return else: target = enemy break angle = angle_between(self.position, target.position) partial_angle = rotate_toward(self.rotation, angle, self.rotation_threshold) self.rotation = partial_angle # use energy to attack enemies. if partial_angle == angle: target.damage(self.get_damage(), 'energy')
def vessel_surface_v_heading(self): if self._cached_vessel_surface_v_heading is None or self.time_elapsed( ): # vessel surface reference frame: x-up, y-north, z-east. # ditching x because heading does not care about vertical speed. surface_velocity = np.array(self.vessel_surface_v())[1:] flat_north = np.array((1, 0)) self._cached_vessel_surface_v_heading = np.rad2deg( angle_between(flat_north, surface_velocity)) return self._cached_vessel_surface_v_heading
def lightMeasurement(self, light): x, y, _ = self.getState() lightVector = light.getIntensityVector(x, y) R = self.T[0:2, 0:2] v_sensor_r = np.matmul(R, np.array((1, 0))) angle_r = np.degrees(utilities.angle_between(lightVector, v_sensor_r)) intensity = np.linalg.norm(lightVector) right_meas = (angle_r / 180) * intensity left_meas = (1 - angle_r / 180) * intensity return right_meas, left_meas
def step(self, data): """Rotates toward 'target' and attacks if possible""" self.cool_down.step() target = self.get_unit_in_range(data.enemies) if target is None: return angle = angle_between(self.position, target.position) partial_angle = rotate_toward(self.rotation, angle, self.rotation_threshold) self.rotation = partial_angle if partial_angle == angle: target.damage(self.get_damage(), 'energy')
def get_deviation(molecule): # Get 1 Pd atom and its neighbours. metal_atoms = [] for atom in molecule.get_atoms(): if atom.get_atomic_number() == 46: metal_atoms.append(atom) if len(metal_atoms) == 2: break chosen_atom = metal_atoms[0] second_atom = metal_atoms[1] # Get plane defined by them. plane_ids = [chosen_atom.get_id()] for bond in molecule.get_bonds(): a1 = bond.get_atom1() a2 = bond.get_atom2() if chosen_atom.get_id() == a1.get_id(): plane_ids.append(a2.get_id()) elif chosen_atom.get_id() == a2.get_id(): plane_ids.append(a1.get_id()) normal = molecule.get_plane_normal(atom_ids=plane_ids) # Get Pd-Pd vector. pos_mat = molecule.get_position_matrix() vector = ( pos_mat[second_atom.get_id()] - pos_mat[chosen_atom.get_id()] ) # Project Pd-Pd vector onto plane. # Apply from https://www.geeksforgeeks.org/vector-projection- # using-python/ projection = vector - ( np.dot(vector, normal)/(np.linalg.norm(normal)**2) )*normal projection_norm = np.linalg.norm(projection) # Get angle between plane and Pd-Pd vector. angle_between_vectors = np.degrees( angle_between(v1=vector, v2=normal) ) return angle_between_vectors, projection_norm
def step(self, data): """Rotates toward 'target' and attacks if possible""" self.cool_down.step() #If no enemy in range does nothing if self.get_unit_in_range(data.enemies) is None: return #If energy enemy is in range it faces and damages it target = self.get_unit_in_range(data.enemies) angle = angle_between(self.position, target.position) partial_angle = rotate_toward(self.rotation, angle, self.rotation_threshold) self.rotation = partial_angle if partial_angle == angle: if target.name == "Energy Enemy": target.damage(self.get_damage(), 'energy') else: return
def step(self, units): if self.target.is_dead(): return False, None # move toward the target radius = euclidean_distance(self.position, self.target.position) if radius <= self.speed: self.target.damage(self.damage, 'fire') return False, None # Rotate toward target and move angle = angle_between(self.position, self.target.position) self.rotation = rotate_toward(self.rotation, angle, self.rotation_threshold) dx, dy = polar_to_rectangular(self.speed, self.rotation) x, y = self.position self.position = x + dx, y + dy return True, None
def step(self, data): """Rotates toward 'target' and slow down it if possible""" self.cool_down.step() target = self.get_unit_in_range(data.enemies) if target is None: return angle = angle_between(self.position, target.position) partial_angle = rotate_toward(self.rotation, angle, self.rotation_threshold) self.rotation = partial_angle if angle != partial_angle or not self.cool_down.is_done(): return None self.cool_down.start() # slow down the target. if partial_angle == angle: if target.grid_speed > 1 / 50: target.grid_speed -= 1 / 600