def calculate_properties(self, *args): if self.visible: ball_position = args[0] BaseRobot.calculate_properties(self, ball_position) if self.desired_position is not None: self.direction["desired_position"] = Util.get_direction(self.position, self.desired_position) if self.enemy1.visible: self.direction["enemy1"] = Util.get_direction(self.position, self.enemy1.position) if self.enemy2.visible: self.direction["enemy2"] = Util.get_direction(self.position, self.enemy2.position) if self.enemy1.visible and self.enemy2.visible: self.intercept_line = [self.enemy1.position, self.enemy2.position] if self.facing_attacking_goal: if self.enemy1.visible and self.enemy2.visible and self.ally.visible: list_of_robots = [self.ally, self.enemy1, self.enemy2] self.can_score = Util.can_score(self.attacking_goal, self, list_of_robots) else: return True else: self.can_score = False self.direction['attacking goal'] = Util.get_direction(self.position, Util.get_midpoint(self.attacking_goal_line))
def calculate_properties(self, *args): if self.visible: ball_position = args[0] BaseRobot.calculate_properties(self, ball_position) if self.desired_position is not None: self.direction["desired_position"] = Util.get_direction(self.position, self.desired_position) if self.enemy1.visible: self.direction["enemy1"] = Util.get_direction(self.position, self.enemy1.position) if self.enemy2.visible: self.direction["enemy2"] = Util.get_direction(self.position, self.enemy2.position) if self.enemy1.visible and self.enemy2.visible: self.intercept_line = [self.enemy1.position, self.enemy2.position]
def has_ball_moved(self, old_ball_position): # check to see if the current ball position is sufficiently far enough away from the old_ball_position distance = Util.get_direction(self.ball_position, old_ball_position)['distance'] if distance >= 5: return True else: return False
def set_desired_position(self, desired_position): self.desired_position = desired_position try: if Util.point_in_defense_zone(self.zones, self.desired_position, self.attacking_goal) or ( Util.point_in_defense_zone(self.zones, self.desired_position, self.defending_goal) and Util.point_in_defense_zone(self.zones, self.ally.position, self.defending_goal) ): # print("[PLANNER GROUP 9] desired position in a naughty place, retreating to centre") self.desired_position = self.centre except: pass self.direction["desired position"] = Util.get_direction(self.position, self.desired_position)
def subtask_complete(self, subtask): if subtask == "turn to ally": angle_to_ally = Util.get_turn_angle(self.robot.heading, self.robot.direction["ally"]["angle"]) return self.robot.within_tolerance_angle(angle_to_ally) elif subtask == "move to receive pass": # if self.robot.desired_position == self.receive_point: angle_to_ally = Util.get_turn_angle(self.robot.heading, self.robot.direction["ally"]["angle"]) distance_to_centre = Util.get_direction(self.robot.position, self.robot.centre)["distance"] return self.robot.within_tolerance_angle(angle_to_ally) and distance_to_centre <= 200 # else: # return False elif subtask == "has ball": return self.has_ball elif subtask == "kicked": return self.kicked
def subtask_complete(self, subtask): """ Returns True if subtask is completed successfully """ if subtask == "turn to ally": angle_to_ally = Util.get_turn_angle(self.robot.heading, self.robot.direction["ally"]['angle']) return self.robot.tolerance_angle("ally") elif subtask == "move to receive pass": # if self.robot.desired_position == self.receive_point: angle_to_ally = Util.get_turn_angle(self.robot.heading, self.robot.direction["ally"]['angle']) distance_to_centre = Util.get_direction(self.robot.position, self.robot.centre)['distance'] return self.robot.tolerance_angle("ally") and distance_to_centre <= self.robot.TOLERANCE_DISTANCE elif subtask == "has ball": return self.has_ball elif subtask == "kicked": return self.kicked
def set_desired_position(self, desired_position): self.desired_position = desired_position self.direction['desired position'] = Util.get_direction(self.position, self.desired_position)