Example #1
0
 def line_change(self):
     self.forward = probability.weighted_choice(self.preference['forward'])
     self.defense = probability.weighted_choice(self.preference['defense'])
     self.current_line = {
         'forward': self.lines['forward'][self.forward],
         'defense': self.lines['defense'][self.defense]
     }
Example #2
0
    def next_play(self):
        pass_base = self.PASS_BASELINE
        shot_base = self.SHOT_BASELINE
        stop_base = self.STOP_BASELINE
        hit_base = self.HIT_BASELINE
        penalty_base = self.PENALTY_BASELINE
        block_base = self.BLOCK_BASELINE
        miss_base = self.MISS_BASELINE
        give_base = self.GIVE_BASELINE
        take_base = self.TAKE_BASELINE
        goal_base = self.GOAL_BASELINE

        if self.zone.name == self.zone.NEUTRAL:
            shot_base = 1
            block_base = 1
            miss_base = 1
            goal_base = 0

        # Loose puck, battle for possession.
        if not self.possession.has_possession:
            takes_it = [(self.home, self.home.lines.average_rating),
                        (self.road, self.home.lines.average_rating)]
            takes_it = weighted_choice(takes_it)
            self.possession.gain_possession(takes_it)

        if self.possession.has_possession == self.home:
            # If badly outclassed the chance exists for rapid puck movement.
            breakaway = self.home.lines.average_rating - self.road.lines.average_rating
            if breakaway < 0:
                breakaway = 0

            advance = [(0, self.road.lines.average_rating),
                       (1, self.home.lines.average_rating),
                       (2, breakaway)]
            advance = weighted_choice(advance)
            self.zone.advance(advance)

        if self.possession.has_possession == self.road:
            breakaway = self.road.lines.average_rating - self.home.lines.average_rating
            if breakaway < 0:
                breakaway = 0

            advance = [(0, self.home.lines.average_rating),
                       (-1, self.road.lines.average_rating),
                       (-2, breakaway)]
            advance = weighted_choice(advance)
            self.zone.advance(advance)

        return weighted_choice(((Pass, pass_base),
                                (Shot, shot_base),
                                (Stop, stop_base),
                                (Hit, hit_base),
                                (Penalty, penalty_base),
                                (Block, block_base),
                                (Miss, miss_base),
                                (Give, give_base),
                                (Take, take_base),
                                (Goal, goal_base)))
Example #3
0
    def next_play(self):
        pass_base = self.PASS_BASELINE
        shot_base = self.SHOT_BASELINE
        stop_base = self.STOP_BASELINE
        hit_base = self.HIT_BASELINE
        penalty_base = self.PENALTY_BASELINE
        block_base = self.BLOCK_BASELINE
        miss_base = self.MISS_BASELINE
        give_base = self.GIVE_BASELINE
        take_base = self.TAKE_BASELINE
        goal_base = self.GOAL_BASELINE

        if self.zone.name == self.zone.NEUTRAL:
            shot_base = 1
            block_base = 1
            miss_base = 1
            goal_base = 0

        # Loose puck, battle for possession.
        if not self.possession.has_possession:
            takes_it = [(self.home, self.home.lines.average_rating),
                        (self.road, self.home.lines.average_rating)]
            takes_it = weighted_choice(takes_it)
            self.possession.gain_possession(takes_it)

        if self.possession.has_possession == self.home:
            # If badly outclassed the chance exists for rapid puck movement.
            breakaway = self.home.lines.average_rating - self.road.lines.average_rating
            if breakaway < 0:
                breakaway = 0

            advance = [(0, self.road.lines.average_rating),
                       (1, self.home.lines.average_rating), (2, breakaway)]
            advance = weighted_choice(advance)
            self.zone.advance(advance)

        if self.possession.has_possession == self.road:
            breakaway = self.road.lines.average_rating - self.home.lines.average_rating
            if breakaway < 0:
                breakaway = 0

            advance = [(0, self.home.lines.average_rating),
                       (-1, self.road.lines.average_rating), (-2, breakaway)]
            advance = weighted_choice(advance)
            self.zone.advance(advance)

        return weighted_choice(
            ((Pass, pass_base), (Shot, shot_base), (Stop, stop_base),
             (Hit, hit_base), (Penalty, penalty_base), (Block, block_base),
             (Miss, miss_base), (Give, give_base), (Take, take_base),
             (Goal, goal_base)))
Example #4
0
 def weighted_defense(self, attribute='overall', exclude=None):
     """
     Select a defenseman on the ice, weighted by a player's attribute.
     """
     choices = [(p, p[attribute]) for p in self.current_line['defense']
                if exclude is None or p not in exclude]
     return probability.weighted_choice(choices)
Example #5
0
 def weighted_defense(self, attribute='overall', exclude=None):
     """
     Select a defenseman on the ice, weighted by a player's attribute.
     """
     choices = [(p, p[attribute]) for p in self.current_line['defense']
                                  if exclude is None or p not in exclude]
     return probability.weighted_choice(choices)
Example #6
0
    def result(self):
        scoring_team = self.home if self.zone.name == self.zone.HOME \
                                 else self.road
        scoring_team = scoring_team.lines

        self.player1 = scoring_team.weighted_choice()

        num_assists = weighted_choice([(0, 10), (1, 20), (2, 70)])
        if num_assists > 0:
            self.player2 = scoring_team.weighted_choice(exclude=[self.player1])
        if num_assists > 1:
            self.player3 = scoring_team.weighted_choice(
                exclude=[self.player1, self.player2])
Example #7
0
    def result(self):
        scoring_team = self.home if self.zone.name == self.zone.HOME \
                                 else self.road
        scoring_team = scoring_team.lines

        self.player1 = scoring_team.weighted_choice()

        num_assists = weighted_choice([(0, 10), (1, 20), (2, 70)])
        if num_assists > 0:
            self.player2 = scoring_team.weighted_choice(exclude=[self.player1])
        if num_assists > 1:
            self.player3 = scoring_team.weighted_choice(exclude=[self.player1,
                                                                 self.player2])
Example #8
0
    def result(self):
        home_face = self.home.lines.forward_by_pos('C')
        road_face = self.road.lines.forward_by_pos('C')

        # Tossed from the faceoff circle?
        if weighted_choice([(True, 20), (False, 80)]):
            home_face = self.home.lines.weighted_forward(exclude=[home_face])
        if weighted_choice([(True, 20), (False, 80)]):
            road_face = self.road.lines.weighted_forward(exclude=[road_face])

        winner = weighted_choice([(self.home, home_face['overall']),
                                  (self.road, road_face['overall'])])

        if winner == self.home:
            self.player1 = home_face
            self.player2 = road_face

            self.possession.gain_possession(self.home)
        else:
            self.player1 = road_face
            self.player2 = home_face

            self.possession.gain_possession(self.road)
Example #9
0
    def result(self):
        home_face = self.home.lines.forward_by_pos('C')
        road_face = self.road.lines.forward_by_pos('C')

        # Tossed from the faceoff circle?
        if weighted_choice([(True, 20), (False, 80)]):
            home_face = self.home.lines.weighted_forward(exclude=[home_face])
        if weighted_choice([(True, 20), (False, 80)]):
            road_face = self.road.lines.weighted_forward(exclude=[road_face])

        winner = weighted_choice([(self.home, home_face['overall']),
                                  (self.road, road_face['overall'])])

        if winner == self.home:
            self.player1 = home_face
            self.player2 = road_face

            self.possession.gain_possession(self.home)
        else:
            self.player1 = road_face
            self.player2 = home_face

            self.possession.gain_possession(self.road)
Example #10
0
 def select_goalie(self):
     selection = probability.weighted_choice([(0, 80), (1, 20)])
     self.current_goalie = self.gk[selection]
Example #11
0
 def line_change(self):
     self.forward = probability.weighted_choice(self.preference['forward'])
     self.defense = probability.weighted_choice(self.preference['defense'])
     self.current_line = {'forward': self.lines['forward'][self.forward],
                          'defense': self.lines['defense'][self.defense]}
Example #12
0
 def select_goalie(self):
     selection = probability.weighted_choice([(0, 80), (1, 20)])
     self.current_goalie = self.gk[selection]