예제 #1
0
    def __init__(self, defender_priorities=[20, 19]):
        super().__init__(continuous=True)

        if len(defender_priorities) != 2:
            raise RuntimeError("defender_priorities should have a length of 2")

        self.add_state(Defense.State.defending,
                       behavior.Behavior.State.running)
        self.add_state(Defense.State.clearing, behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
                            Defense.State.defending, lambda: True,
                            "immediately")
        self.add_transition(Defense.State.defending, Defense.State.clearing,
                            lambda: self.should_clear_ball(),
                            "Clearing the ball")
        self.add_transition(Defense.State.clearing, Defense.State.defending,
                            lambda: not self.should_clear_ball(),
                            "Done clearing")

        goalie = submissive_goalie.SubmissiveGoalie()
        goalie.shell_id = main.root_play().goalie_id
        self.add_subbehavior(goalie, "goalie", required=False)

        # Add the defenders
        for num, priority in enumerate(defender_priorities):
            defender = submissive_defender.SubmissiveDefender()
            self.add_subbehavior(defender,
                                 'defender' + str(num + 1),
                                 required=False,
                                 priority=priority)

        self.debug = True

        self.kick_eval = robocup.KickEvaluator(main.system_state())
예제 #2
0
    def __init__(self):
        super().__init__(continuous=True)

        goalie = submissive_goalie.SubmissiveGoalie()
        goalie.shell_id = main.root_play().goalie_id
        self.add_subbehavior(goalie, "goalie", required=True)

        self.add_state(WingerWall.State.defending,
                       behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
                            WingerWall.State.defending, lambda: True,
                            "immediately")

        self.aggression = 1
        self.kick_eval = robocup.KickEvaluator(main.system_state())
        self.wingers = []
        self.forwards = []
        self.max_wingers = 3
        self.max_wall = 3
        self.assigned_wingers = 0
        # List of tuples of (class score, robot obj)

        self.kick_eval.excluded_robots.clear()

        for bot in main.our_robots():
            self.kick_eval.add_excluded_robot(bot)
예제 #3
0
def eval_shot(from_point, excluded_robots=[]):
    kick_eval = robocup.KickEvaluator(main.system_state())
    for r in excluded_robots:
        kick_eval.add_excluded_robot(r)
    point, chance = kick_eval.eval_pt_to_opp_goal(from_point)

    if from_point.y > (constants.Field.Length / 2):

        return chance
    else:
        # The shot is invalid
        return 0
예제 #4
0
    def __init__(self):
        super().__init__(continuous=True)
        #Below params are described above @properties
        self._ratio = 0.2
        #This threshold is lower than mark to ensure we get goal side of the opponent fast,
        #then back off based on ratio

        self._mark_line_thresh = constants.Robot.Radius * 4
        self._mark_robot = None
        self._mark_point = None

        self._target_point = None

        self.add_transition(behavior.Behavior.State.start,
                            behavior.Behavior.State.running, lambda: True,
                            "immediately")
        self.kick_eval = robocup.KickEvaluator(main.system_state())
        self.mark_pos = None
        self.adjusted_mark_pos = None
예제 #5
0
    def __init__(self):
        super().__init__(continuous=True)

        self.debug = False

        self.add_transition(behavior.Behavior.State.start,
                            behavior.Behavior.State.running, lambda: True,
                            'immediately')

        self.marks = []

        if (main.game_state().is_their_direct()):
            self.intercept = (constants.Field.OurGoalSegment.center() -
                              main.ball().pos) * 0.25 + main.ball().pos
            self.add_subbehavior(skills.move.Move(self.intercept),
                                 'intercept direct',
                                 required=False,
                                 priority=5)

        for i in range(3):
            mark_i = skills.mark.Mark()
            mark_i.ratio = 0.7
            self.add_subbehavior(mark_i,
                                 'mark' + str(i),
                                 required=False,
                                 priority=3 - i)
            self.marks.append(mark_i)

        self.kick_eval = robocup.KickEvaluator(main.system_state())
        self.kick_eval.debug = True
        for i, robot in enumerate(main.our_robots()):
            self.kick_eval.add_excluded_robot(robot)

        for i, robot in enumerate(main.their_robots()):
            self.kick_eval.add_excluded_robot(robot)

        their_kicker = min(main.their_robots(),
                           key=lambda opp: opp.pos.dist_to(main.ball().pos))
        self.kick_eval.add_excluded_robot(their_kicker)
def goalside_mark_segment(mark_pos, robot, ball=False, kick_eval=None):

    if kick_eval is None:
        kick_eval = robocup.KickEvaluator(main.system_state())

    #Define the segments where the defender can go closest the goal
    offset = constants.Robot.Radius
    goal_rect_padded = constants.Field.OurGoalZoneShapePadded(offset)

    #Find best shot point from threat
    kick_eval.add_excluded_robot(robot)
    shot_pt, shot_score = kick_eval.eval_pt_to_our_goal(mark_pos)
    kick_eval.excluded_robots.clear()

    #End the mark line segment 1 radius away from the opposing robot
    #Or 1 ball radius away if marking a position
    if not ball:
        adjusted_mark_pos = mark_pos - (
            mark_pos - shot_pt).normalized() * 2 * constants.Robot.Radius
    else:
        adjusted_mark_pos = mark_pos - (mark_pos - shot_pt
                                        ).normalized() * constants.Ball.Radius

    shot_seg = robocup.Segment(adjusted_mark_pos, shot_pt)
    tmp = goal_rect_padded.segment_intersection(shot_seg)

    if tmp is None:
        return shot_seg, shot_pt

    intersections = sorted(tmp, key=lambda pt: pt.y, reverse=True)

    #Correction for when there is no segment because the opposing robot is inside a radius of our goalzone
    if len(intersections) == 0:
        intersections.append(adjusted_mark_pos)

    return robocup.Segment(adjusted_mark_pos, intersections[0]), shot_pt
def estimate_risk_score(pos, ignore_robots=[]):
    # Caches some kick eval functions
    max_time = 1
    max_ball_vel = 8  # m/s per the rules
    est_turn_vel = 8  # rad/s per a random dice roll (Over estimates oppnents abilities)

    kick_eval = robocup.KickEvaluator(main.system_state())

    for r in ignore_robots:
        kick_eval.add_excluded_robot(r)

    _, pass_score = kick_eval.eval_pt_to_robot(main.ball().pos, pos)
    shot_pt, shot_score = kick_eval.eval_pt_to_our_goal(pos)

    # Dist to ball
    ball_pos_vec = pos - main.ball().pos
    dist = ball_pos_vec.mag()
    max_dist = robocup.Point(constants.Field.Width,
                             constants.Field.Length).mag()

    # Closest opp robot
    closest_opp_bot = evaluation.opponent.get_closest_opponent(main.ball().pos)
    delta_angle = ball_pos_vec.angle() - \
                  predict_kick_direction(closest_opp_bot)
    delta_angle = math.atan2(math.sin(delta_angle), math.cos(delta_angle))

    # Underestimates max time to execute on ball
    # Assumes perfect opponent
    time = dist / max_ball_vel + math.fabs(delta_angle) / est_turn_vel
    # Limits to max time so we can invert it later on
    time = min(time, max_time)

    # Center, Dist, Angle
    pos_score = evaluation.field.field_pos_coeff_at_pos(pos, 0.05, 0.3, 0.05,
                                                        False)
    space_coeff = evaluation.field.space_coeff_at_pos(pos, ignore_robots,
                                                      main.our_robots())

    # Delta angle between pass recieve and shot
    delta_angle = ball_pos_vec.angle() - (shot_pt - pos).angle()
    delta_angle = math.atan2(math.sin(delta_angle), math.cos(delta_angle))
    angle_coeff = math.fabs(delta_angle) / math.pi

    # Shot only matters if its a good pass
    # Add pass back in for checking if pass is good (while shot is not)
    #
    # Add in time to weight closer points higher
    #
    # Pos is weighted higher to remove bad positions from calculations
    #
    # Space is weighted in so it is weighted towards lower density areas
    #
    # Delta angle for shot is weighted in so easier shots are weighted higher
    #
    # Distance to the ball squared

    #  Pass, Time, Pos, Space, Angle
    weights = [0.1, 0.1, 2, 0.4, 0.3, 1]
    score = weights[0] * (shot_score * pass_score + pass_score) / 2 + \
            weights[1] * (max_time - time) + \
            weights[2] * pos_score + \
            weights[3] * (1 - space_coeff) + \
            weights[4] * angle_coeff + \
            weights[5] * (1 - dist / max_dist)**2

    return score / sum(weights)
예제 #8
0
def eval_shot(from_point, excluded_robots=[]):
    kick_eval = robocup.KickEvaluator(main.system_state())
    for r in excluded_robots:
        kick_eval.add_excluded_robot(r)
    point, chance = kick_eval.eval_pt_to_opp_goal(from_point)
    return chance
예제 #9
0
    def __init__(self):
        super().__init__(continuous=False)

        for s in AdaptiveFormation.State:
            self.add_state(s, behavior.Behavior.State.running)

        # Dribbling skill
        self.dribbler = None
        # Dribble start point
        self.dribble_start_pt = robocup.Point(0, 0)

        # Kicker for a shot
        self.kick = None
        # Controls robots while passes are being set up
        self.midfielders = None

        # State Decision Variables
        self.shot_chance = 0
        self.pass_score = 0
        # Prev State Decision Variables
        self.prev_shot_chance = 0
        self.prev_pass_score = 0
        # Used to keep dribble within rules
        self.check_dribbling_timer = 0
        self.check_dribbling_timer_cutoff = 100

        self.kick_eval = robocup.KickEvaluator(main.system_state())

        # Add transitions
        self.add_transition(behavior.Behavior.State.start,
                            AdaptiveFormation.State.collecting, lambda: True,
                            'immediately')

        self.add_transition(
            AdaptiveFormation.State.collecting,
            AdaptiveFormation.State.dribbling,
            lambda: self.subbehavior_with_name('defend').state == behavior.Behavior.State.completed,
            'Ball Collected')

        self.add_transition(
            AdaptiveFormation.State.dribbling, AdaptiveFormation.State.passing,
            lambda: self.dribbler_has_ball() and self.should_pass_from_dribble() and not self.should_shoot_from_dribble(),
            'Passing')

        self.add_transition(
            AdaptiveFormation.State.dribbling,
            AdaptiveFormation.State.shooting,
            lambda: self.dribbler_has_ball() and self.should_shoot_from_dribble(),
            'Shooting')

        self.add_transition(
            AdaptiveFormation.State.dribbling,
            AdaptiveFormation.State.clearing,
            lambda: self.dribbler_has_ball() and self.should_clear_from_dribble() and not self.should_pass_from_dribble() and not self.should_shoot_from_dribble(),
            'Clearing')

        self.add_transition(
            AdaptiveFormation.State.passing, AdaptiveFormation.State.dribbling,
            lambda: self.subbehavior_with_name('pass').state == behavior.Behavior.State.completed,
            'Passed')

        # Reset to collecting when ball is lost at any stage
        self.add_transition(AdaptiveFormation.State.dribbling,
                            AdaptiveFormation.State.collecting,
                            lambda: not self.dribbler_has_ball(),
                            'Dribble: Ball Lost')
        self.add_transition(
            AdaptiveFormation.State.passing,
            AdaptiveFormation.State.collecting,
            lambda: self.subbehavior_with_name('pass').state == behavior.Behavior.State.cancelled or self.subbehavior_with_name('pass').state == behavior.Behavior.State.failed,
            'Passing: Ball Lost')
        self.add_transition(
            AdaptiveFormation.State.shooting,
            AdaptiveFormation.State.collecting,
            lambda: self.subbehavior_with_name('kick').is_done_running(),
            'Shooting: Ball Lost / Shot')
        self.add_transition(
            AdaptiveFormation.State.clearing,
            AdaptiveFormation.State.collecting,
            lambda: self.subbehavior_with_name('clear').is_done_running(),
            'Clearing: Ball Lost')