Пример #1
0
def execute_field_goal(game):
    """
    Executes a field goal play
    """
    chance_mod = random_in_range(-10, 10)
    chance = ((100
               * (game.offense.get_player('K', 1).kick_accuracy) / 100.0)
              + (60 * (game.offense.get_player('K', 1).kick_power) / 100.0)
              - (2.5 * game.yard_line)
              + (3 * chance_mod)
              + game.kick_mod
              + random_variability())

    if chance > 100:
        chance = 100

    if chance < 1 and random_chance(1):
        chance = 1

    if random_chance(chance):
        game.offense.score += 3

    game = spend_time(3, 7, 3, False)

    return game
Пример #2
0
def execute_extra_point(game):
    """
    Executes an extra point play
    """
    two_point = determine_two_point_conversion(game)

    if two_point:
        return execute_two_point_conversion(game)

    kick_mod = random_in_range(-10, 10)
    chance = ((100 * game.offense.get_player('K', 1).kick_accuracy / 100.0)
            + (60 * (game.offense.get_player('K', 1).kick_power / 100.0))
            - (15 * 5)
            + (2 * game.kick_mod)
            + random_variability())

    if chance > 100:
        chance = 100

    chance += game.kick_mod

    if random_chance(chance):
        game.offense.score += 1

    #TODO log missed extra point

    return game
Пример #3
0
def execute_two_point_conversion(game):
    """
    Executes two point conversion
    """
    success = False
    if random_chance(game.offense.gameplan.o_run):
        game =  execute_run_play(game)
    else:
        game = execute_pass_play(game)

    #TODO figure out how to unravel the mess of two point conversion play logic vs. static play logging

    return game
Пример #4
0
def run(game):
    """
    Primary entry point for game simulation
    """
    pdb.set_trace()
    if random_chance(50):
        game.offense = game.away
        game.defense = game.home
    else:
        game.offense = game.home
        game.defense = game.away

    game.kicking_team = game.defense

    while game.time > 0:
        if game.overtime is False:
            if game.last_time > 2700 and game.time <= 2700:
                game.quarter = 2
            if game.last_time > 1800 and game.time <= 1800:
                game.quarter = 3
                game.time = 1800

                if game.kicking_team != game.offense:
                    tmp = game.offense
                    game.offense = game.defense
                    game.defense = tmp

                #TODO implement second half kickoff
            if game.last_time > 900 and game.time <= 900:
                game.quarter = 4
        else:
            if game.offense.score != game.defense.score:
                game.time = 0

        if game.down < 4:
            game = determine_play(game)
        elif game.down == 4:
            game = execute_fourth_down(game)
        else:
            game = execute_turnover(game)

        if game.time <= 0:
            foo = False
            #TODO check overtime

    return game
Пример #5
0
def execute_pass_play(game):
    """
    Executes a pass play
    """
    pass_type_mod = 0
    sack_mod = 0
    #TODO implement sack_mod based on defensive play call
    pass_type = 0
    #TODO implement pass_type calculation

    if pass_type is 3:
        # if total run plays - 3 >= total pass plays in this game by the offense
        pass_type_mod = 5
        # else pass_type_mod = -5
    if game.pass_type is 4:
        pass_type_mod = 10

    if random_chance(determine_completion_chance(game) + pass_type_mod):
        return execute_completed_pass(game, pass_type)
    else:
        incompletion_chance = 85.0 + (game.offense.pass_blocking / 5.0) \
            - (1.5 * (100 - game.defense.gameplan.d_run) / 100.0) \
            + (2.0 * game.play_mod) \
            + (0.5 * (game.offense.team_mod - game.defense.team_mod)) \
            + ((100.0 - game.offense.gameplan.o_aggression) / 100.0) \
            - (game.defense.gameplan.d_aggression / 100.0) \
            + random_variability()

        choices = [
            (1, int(determine_sack_chance(game), sack_mod)),
            (2, 0),
            (3, int(incompletion_chance))
        ]
        result = random_weighted_choice(choices)

        if result == 1:
            print('sack!')  # sack()
            #TODO implement sack() method
        elif result == 2:
            print('interception!')  # interception()
            #TODO implement interception() method
        # elif check_scramble():
        else:
            print('incomplete!')  # incompletion()
Пример #6
0
def execute_run_play(game):
    """
    Executes a run play
    """
    rusher = None
    break_stat = 50.0
    rb1 = game.offense.get_player('RB', 1)
    fb = game.offense.get_player('FB', 1)
    te = game.offense.get_player('TE', 1)

    if game.togo is 1:
        break_stat = fb.speed * 0.75
        rusher = fb
    else:
        break_stat = rb1.agility
        rusher = rb1

    rush_mod = random.randint(-4, 3)
    min_rush = (-3.0
                + (5.0 * (game.offense.run_blocking / 100.0))
                + (3.25 * (rusher.break_tackle / 100.0))
                + (0.5 * (break_stat / 100.0))
                + (1.25 * (fb.run_blocking / 100.0))
                + (0.25 * (te.run_blocking / 100.0))
                - (5.0 * (game.defense.run_defense / 100.0))
                + (1.0 * game.play_mod)
                + (0.1 * (game.offense.team_mod - game.defense.team_mod))
                + (0.25 * game.run_mod)
                - (0.5 * game.defense.gameplan.d_run / 100.0)
                + (1.25 * (((100 - game.offense.gameplan.o_aggression)
                            - game.defense.gameplan.d_aggression) / 100.0))
                + random_variability()
                + rush_mod)

    if (game.yard_line > 95) and (min_rush < -1):
        min_rush = -1

    if (game.yard_line >= 99) and (min_rush < 0):
        if random_chance(rusher.break_tackle - 20):
            min_rush = 0

    rush_mod = random.randint(-3, 4)
    max_rush = (3.0
                + (6.25 * (game.offense.run_blocking / 100.0))
                + (7.5 * (rusher.break_tackle / 100.0))
                + (2.5 * (break_stat / 100.0))
                + (0.5 * (rusher.speed / 100.0))
                + (2.5 * (fb.run_blocking / 100.0))
                + (1.5 * (te.run_blocking / 100.0))
                + (1.0 * game.play_mod)
                + (0.1 * (game.offense.team_mod - game.defense.team_mod))
                + (0.25 * game.run_mod)
                - (0.5 * game.defense.gameplan.d_run / 100.0)
                + (1.25 * ((game.offense.gameplan.o_aggression
                - (100 - game.defense.gameplan.d_aggression)) / 100.0))
                + random_variability()) + rush_mod

    if game.defense.gameplan.d_style is '43':
        max_rush = (max_rush
                    - (8.5 * (game.defense.run_defense / 100.0))
                    - (3.0 * (game.defense.get_player('LOLB', 1).tackling / 100.0))
                    - (3.0 * (game.defense.get_player('MLB', 1).tackling / 100.0))
                    - (3.0 * (game.defense.get_player('ROLB', 1).tackling / 100.0)))

        if random_chance(100 - rusher.concentration) and random_chance(game.defense.run_defense / 2):
            min_rush -= 1

    else:
        max_rush = (max_rush
                    - (1.5 * (game.defense.run_defense / 100.0))
                    - (4.0 * (game.defense.get_player('LOLB', 1).tackling / 100.0))
                    - (4.0 * (game.defense.get_player('LILB', 1).tackling / 100.0))
                    - (4.0 * (game.defense.get_player('RILB', 1).tackling / 100.0))
                    - (4.0 * (game.defense.get_player('ROLB', 1).tackling / 100.0)))

        if random_chance(rusher.concentration) and random_chance(
                (game.defense.get_player('LOLB', 1).tackling
                 + game.defense.get_player('LILB', 1).tackling
                 + game.defense.get_player('RILB', 1).tackling
                 + game.defense.get_player('ROLB', 1).tackling)) / 8:
            max_rush -= 1

    if min_rush > max_rush:
        min_rush = max_rush

    gain = random.randint(int(min_rush), int(max_rush))

    if (gain >= 7
            or random_chance(break_stat / 4.0 + random_variability())
            and random_chance(rusher.speed / 1.5)):
        max_additional = ((22.0 * (rusher.speed / 100.0))
                          - (2.5 * (game.defense.get_player('LCB', 1).tackling / 100.0))
                          - (2.5 * (game.defense.get_player('RCB', 1).tackling / 100.0))
                          - (3.5 * (game.defense.get_player('SS', 1).tackling / 100.0))
                          - (3.5 * (game.defense.get_player('FS', 1).tackling / 100.0))
                          + (2.0 * game.play_mod)
                          + (0.5 * game.run_mod)
                          + (0.25 * (game.offense.team_mod - game.defense.team_mod))
                          + random_variability())

        if max_additional < 1:
            max_additional = 1

        gain += random.uniform(0, max_additional)

        big_play_mod = 0

        while random_chance(rusher.speed / 2 + (6 * big_play_mod)):
            max_additional = ((20.0 * (rusher.speed / 100.0))
                              - (2.5 * (game.defense.get_player('LCB', 1).tackling / 100.0))
                              - (2.5 * (game.defense.get_player('RCB', 1).tackling / 100.0))
                              - (3.5 * (game.defense.get_player('SS', 1).tackling / 100.0))
                              - (3.5 * (game.defense.get_player('FS', 1).tackling / 100.0))
                              + (2.0 * game.play_mod)
                              + (0.5 * game.run_mod)
                              + (0.25 * (game.offense.team_mod - game.defense.team_mod))
                              + random_variability())

            if max_additional < 1:
                max_additional = 1

            gain += random.uniform(0, max_additional)

            if random_chance(break_stat / 2):
                big_play_mod += 1

            if rusher.speed / 2 + (8 * big_play_mod) > 100:
                gain = 101

    if random_chance(105 - rusher.break_tackle):
        gain -= 1

    if gain < -5 and random_chance(90):
        gain = -5

    if gain < 0:
        weighted_choices = [(game.offense.get_player('LT', 1), 1),
                            (game.offense.get_player('LG', 1), 1),
                            (game.offense.get_player('C', 1), 1),
                            (game.offense.get_player('RG', 1), 1),
                            (game.offense.get_player('RT', 1), 1)]

        allowed_loss = random_weighted_choice(weighted_choices)

        # TODO record TFL allowed here
    elif gain > 5:
        foo = 0
        # TODO pancake logic, record pancacke here

    td = 0
    fumble = False

    if gain >= game.yard_line:
        gain = game.yard_line
        td = 1
    else:
        if game.defense.gameplan.d_style is '43':
            fum_chance = ((1.8 * rusher.concentration)
                          - (0.35 * game.defense.run_defense)
                          - (0.05 * game.defense.get_player('LOLB', 1).tackling)
                          - (0.05 * game.defense.get_player('MLB', 1).tackling)
                          - (0.05 * game.defense.get_player('ROLB', 1).tackling)
                          + (0.2 * (((100 - game.offense.gameplan.o_aggression)
                                     - game.defense.gameplan.d_aggression)))
                          + random_variability())
        else:
            fum_chance = ((1.8 * rusher.concentration)
                          - (0.1 * game.defense.run_defense)
                          - (0.1 * game.defense.get_player('LOLB', 1).tackling)
                          - (0.1 * game.defense.get_player('LILB', 1).tackling)
                          - (0.1 * game.defense.get_player('RILB', 1).tackling)
                          - (0.1 * game.defense.get_player('ROLB', 1).tackling)
                          + (0.2 * (((100 - game.offense.gameplan.o_aggression)
                                     - game.defense.gameplan.d_aggression)))
                          + random_variability())

        if fum_chance < 5:
            fum_chance = 5

        if int(random.uniform(0, int(fum_chance))) == 0:
            if (game.yard_line - gain) < 100.0:
                fumble = True

    fumble_forcer = game.defense.get_player('LDE', 1)

    if fumble:
        if gain < 6 and (random_chance(95) or random_chance(5)):
            if game.defense.gameplan.d_style is '43':
                choices = [
                    (game.defense.get_player('LOLB', 1), game.defense.get_player('LOLB', 1).tackling),
                    (game.defense.get_player('MLB', 1), game.defense.get_player('MLB', 1).tackling),
                    (game.defense.get_player('ROLB', 1), game.defense.get_player('ROLB', 1).tackling)
                ]
                fumble_forcer = random_weighted_choice(choices)
            else:
                choices = [
                    (game.defense.get_player('LOLB', 1), game.defense.get_player('LOLB', 1).tackling),
                    (game.defense.get_player('LILB', 1), game.defense.get_player('LILB', 1).tackling),
                    (game.defense.get_player('RILB', 1), game.defense.get_player('RILB', 1).tackling),
                    (game.defense.get_player('ROLB', 1), game.defense.get_player('ROLB', 1).tackling)
                ]
                fumble_forcer = random_weighted_choice(choices)
        else:
            choices = [
                (game.defense.get_player('LCB', 1), game.defense.get_player('LCB', 1).tackling),
                (game.defense.get_player('RCB', 1), game.defense.get_player('RCB', 1).tackling),
                (game.defense.get_player('SS', 1), game.defense.get_player('SS', 1).tackling),
                (game.defense.get_player('FS', 1), game.defense.get_player('FS', 1).tackling)
            ]
            fumble_forcer = random_weighted_choice(choices)

    #TODO finish implementing, including return type, play logging, turnover execution


    return game
Пример #7
0
def execute_completed_pass(game, pass_type):
    """
    Executes a completed pass
    """
    pass_mod = random.randint(-5, 5)

    max_gain = (3.25
                + (10.0 * (game.offense.get_player('QB', 1).throw_power / 100.0))
                + (1.5 * game.play_mod)
                + (0.15 * (game.offense.team_mod - game.defense.team_mod))
                + (0.5 * game.pass_mod))

    gain = random.randint(int(1 + pass_mod), int(max_gain + pass_mod))

    if gain > 9:
        foo = 0
        #TODO implement pancacke logic

    if pass_type is 2:
        gain = random.randint(int(game.offense.get_player('QB', 1).throw_power / 2
                                  + pass_mod),
                              int(game.offense.get_player('QB', 1).throw_power / 2
                                  + max_gain + pass_mod))

    receiver = None

    check_down = False

    pass_mod = random.randint(-5, 5)

    ag_play = (72.5 +
               game.offense.get_player('QB', 1).throw_power / 10
               + ((game.offense.gameplan.o_aggression - 50) / 50) + ((game.defense.gameplan.d_aggression - 50) / 50)
               - (game.defense.get_player('CB', 1).coverage - 50) / 7.5
               - (game.defense.get_player('CB', 1).coverage - 50) / 7.5
               + game.pass_mod
               + game.play_mod
               + random_variability())

    if pass_type is 0:
        ag_play -= 5

    if pass_type is 1:
        ag_play += 5

    if ag_play > 80:
        ag_play = 80
    elif ag_play < 65:
        ag_play = 65

    if pass_type is 3:
        ag_play = 95

    if random_chance(ag_play):
        lb_coverage = (game.defense.get_player('LOLB', 1).coverage
                       + game.defense.get_player('ROLB', 1).coverage) - 100

        weighted_choices = [
            (game.offense.get_player('WR', 1),
             int((game.offense.get_player('WR', 1).catching * 3.05
                  + game.offense.get_player('WR', 1).acceleration
                  - ((game.defense.get_player('LCB', 1).coverage - 50.0) / 25.0)
                  + random_variability()))),
            (game.offense.get_player('WR', 2),
             int((game.offense.get_player('WR', 2).catching * 3.05
                  + game.offense.get_player('WR', 2).acceleration
                  - ((game.defense.get_player('RCB', 1).coverage - 50.0) / 25.0)
                  + random_variability()))),
            (game.offense.get_player('WR', 3),
             int((game.offense.get_player('WR', 3).catching * 3.05
                  + game.offense.get_player('WR', 3).acceleration
                  - ((game.defense.get_player('SS', 1).coverage - 50.0) / 50.0)
                  - ((game.defense.get_player('FS', 1).coverage - 50.0) / 50.0)
                  + random_variability()))),
            (game.offense.get_player('TE', 1),
             int((game.offense.get_player('TE', 1).catching * 3.05
                  - lb_coverage / 50.0
                  - ((game.offense.gameplan.o_aggression - 50.0) / 50.0)
                  + game.offense.get_player('TE', 1).speed / 2.0
                  + random_variability())))
        ]

        receiver = random_weighted_choice(weighted_choices)
    else:
        weighted_choices = [
            (game.offense.get_player('TE', 1), int((game.offense.get_player('TE', 1).catching * 1.5) + 1)),
            (game.offense.get_player('RB', 1), game.offense.get_player('RB', 1).catching),
            (game.offense.get_player('RB', 2), game.offense.get_player('RB', 2).catching),
            (game.offense.get_player('FB', 1), game.offense.get_player('FB', 1).catching)
        ]

        receiver = random_weighted_choice(weighted_choices)

        if receiver is game.offense.get_player('RB', 1):
            weighted_choices = [
                (game.offense.get_player('RB', 1),
                 game.offense.get_player('RB', 1).catching * 2
                 + game.offense.get_player('RB', 2).catching * 2 + 1),
                (game.offense.get_player('FB', 1),
                 int(game.offense.get_player('FB', 1).catching / 2 + 1))
            ]

            receiver = random_weighted_choice(weighted_choices)

            if receiver is game.offense.get_player('RB', 1):
                weighted_choices = [
                    (game.offense.get_player('RB', 1),
                     game.offense.get_player('RB', 1).catching * 2 + 1),
                    (game.offense.get_player('RB', 2),
                     game.offense.get_player('RB', 2).catching * 2 + 1)
                ]

                receiver = random_weighted_choice(weighted_choices)

    if pass_type is 4:
        weighted_choices = [
            (game.offense.get_player('RB', 1),
             game.offense.get_player('RB', 1) * 2 + 1),
            (game.offense.get_player('RB', 2),
             game.offense.get_player('RB', 2) * 2 + 1)
        ]

        receiver = random_weighted_choice(weighted_choices)

    break_stat = 50

    if receiver is game.offense.get_player('WR', 1):
        break_stat = receiver.acceleration

        if random_chance(105 - receiver.acceleration):
            check_down = True
    elif receiver is game.offense.get_player('WR', 2):
        break_stat = receiver.acceleration

        if random_chance(105 - receiver.acceleration):
            check_down = True
    elif receiver is game.offense.get_player('WR', 3):
        break_stat = receiver.acceleration

        if random_chance(105 - receiver.acceleration):
            check_down = True
    elif receiver is game.offense.get_player('TE', 1):
        break_stat = receiver.speed

        if random_chance(105 - receiver.speed / 1.5 + random_variability()):
            check_down = True
    elif receiver is game.offense.get_player('RB', 1) or game.offense.get_player('RB', 2):
        break_stat = receiver.agility

        if random_chance(105 - receiver.agility / 1.75 + random_variability()):
            check_down = True
    elif receiver is game.offense.get_player('FB', 1):
        break_stat = receiver.break_tackle

        if random_chance(105 - receiver.speed / 2.0 + random_variability()):
            check_down = True

    pass_mod = random.randint(-3, 3)

    if check_down:
        max_gain = (1.0
                    + (4.0 * (receiver.speed / 100.0))
                    - (0.25 * (game.defense.get_player('LCB', 1).tackling / 100.0))
                    - (0.25 * (game.defense.get_player('RCB', 1).tackling / 100.0))
                    - (0.25 * (game.defense.get_player('SS', 1).tackling / 100.0))
                    - (0.25 * (game.defense.get_player('FS', 1).tackling / 100.0))
                    + (1.0 * ((game.offense.gameplan.o_aggression - (100 - game.defense.gameplan.d_aggression)) / 100.0))
                    - (1.0 * (100 - game.defense.gameplan.d_run) / 100.0)
                    + pass_mod
                    + random_variability())

        while not random_chance(game.defense.get_player('SS', 1).tackling + 1)\
            and not random_chance(game.defense.get_player('FS', 1).tackling + 1)\
                and (max_gain < 200):
            max_gain += 0.25
    else:
        max_gain = (2.0
                    + (12.0 * (receiver.speed / 100.0))
                    - (0.5 * (game.defense.get_player('LCB', 1).tackling / 100.0))
                    - (0.5 * (game.defense.get_player('RCB', 1).tackling / 100.0))
                    - (0.5 * (game.defense.get_player('SS', 1).tackling / 100.0))
                    - (0.5 * (game.defense.get_player('FS', 1).tackling / 100.0))
                    + (1.0 * ((game.offense.gameplan.o_aggression - (100 - game.defense.gameplan.d_aggression)) / 100.0))
                    - (1.0 * (100 - game.defense.gameplan.d_run) / 100.0) + pass_mod + random_variability())

        while not random_chance(game.defense.get_player('SS', 1).tackling + 1)\
            and not random_chance(game.defense.get_player('FS', 1).tackling + 1)\
                and (max_gain < 200):
            max_gain += 0.5

    if max_gain < 0:
        max_gain = 0

    gain += random.randint(0, int(max_gain))

    break_free = (break_stat / 2.5 + random.randint(-5, 5) + random_variability())

    if check_down:
        break_free = (break_stat / 5.0 + random.randint(-5, 5) + random_variability())

    if break_free < 15:
        break_free = 15

    num_free = 0

    while random_chance(break_free + (10 * num_free)) and gain <= 100:
        max_gain = (2.5
                    + (22.5 * (receiver.speed / 100.0))
                    - (3.5 * (game.defense.get_player('LCB', 1).tackling / 100.0))
                    - (3.5 * (game.defense.get_player('RCB', 1).tackling / 100.0))
                    - (5.5 * (game.defense.get_player('SS', 1).tackling / 100.0))
                    - (5.5 * (game.defense.get_player('FS', 1).tackling / 100.0))
                    + (2.0 * game.play_mod)
                    + (0.25 * (game.offense.team_mod - game.defense.team_mod))
                    + (0.25 * (game.offense.gameplan.o_aggression / 100.0))
                    + random_variability())

        if max_gain < 1:
            max_gain = 1

        gain += random.randint(0, int(max_gain))

        if random_chance(receiver.speed / 1.5 + random_variability()):
            num_free += 1

        if (break_free + (10 * num_free)) > 100:
            gain = 101

    if gain < -2:
        gain = -2

    td = 0

    fumble = False

    if gain >= game.yard_line:
        gain = game.yard_line
        td = 1
    else:
        td = 0

        fum_chance = ((1.55 * receiver.concentration)
                      - (0.1 * game.defense.get_player('LCB', 1).tackling)
                      - (0.1 * game.defense.get_player('RCB', 1).tackling)
                      - (0.15 * game.defense.get_player('SS', 1).tackling)
                      - (0.15 * game.defense.get_player('FS', 1).tackling)
                      + (0.2 * (((100 - game.offense.gameplan.o_aggression)
                                 - game.defense.gameplan.d_aggression))) + random_variability())

        if fum_chance < 5:
            fum_chance = 5

        if int(random.uniform(0, int(fum_chance))) == 0:
            if (game.yard_line - gain) < 100:
                fumble = True

    fumble_forcer = game.defense.get_player('RDE', 1)

    if fumble:
        if ((gain < 10) and random_chance(95)) or random_chance(5):
            if game.defense.gameplan.d_style is '43':
                choices = [
                    (game.defense.get_player('LOLB', 1), game.defense.get_player('LOLB', 1).tackling + 1),
                    (game.defense.get_player('MLB', 1), game.defense.get_player('MLB', 1).tackling + 1),
                    (game.defense.get_player('ROLB', 1), game.defense.get_player('ROLB', 1).tackling + 1),
                    (game.defense.get_player('LCB', 1), game.defense.get_player('LCB', 1).tackling * 2
                     - game.defense.get_player('LCB', 1).coverage + 1),
                    (game.defense.get_player('LCB', 2), game.defense.get_player('LCB', 2).tackling * 2
                     - game.defense.get_player('LCB', 2).coverage + 1)
                ]
                fumble_forcer = random_weighted_choice(choices)
            else:
                choices = [
                    (game.defense.get_player('LOLB', 1), game.defense.get_player('LOLB', 1).tackling + 1),
                    (game.defense.get_player('LILB', 1), game.defense.get_player('LILB', 1).tackling + 1),
                    (game.defense.get_player('RILB', 1), game.defense.get_player('RILB', 1).tackling + 1),
                    (game.defense.get_player('ROLB', 1), game.defense.get_player('ROLB', 1).tackling + 1),
                    (game.defense.get_player('LCB', 1), game.defense.get_player('LCB', 1).tackling + 1),
                    (game.defense.get_player('RCB', 1), game.defense.get_player('RCB', 1).tackling + 1)
                ]
                fumble_forcer = random_weighted_choice(choices)
        else:
            choices = [
                (game.defense.get_player('LCB', 1), game.defense.get_player('LCB', 1).tackling + 1),
                (game.defense.get_player('RCB', 1), game.defense.get_player('RCB', 1).tackling + 1),
                (game.defense.get_player('SS', 1), game.defense.get_player('SS', 1).tackling + 1),
                (game.defense.get_player('FS', 1), game.defense.get_player('FS', 1).tackling + 1)
            ]
            fumble_forcer = random_weighted_choice(choices)

    return receiver.name, gain, td, fumble
Пример #8
0
def execute_kickoff(game):
    """
    Executes a kickoff play
    """
    kicker = game.offense.get_player('K', 1)
    returner = game.defense.get_player('KR', 1)
    onside = determine_onside_kick(game)

    if onside:
        return execute_onside_kickoff(game)

    chance_mod = random_in_range(-10, 10)
    #TODO great blocking implementation
    great_blocking = False
    return_mod = random_in_range(-5, 5)

    #TODO if great blocking

    back_of_endzone = False
    out_of_bounds = False

    max_kick = (35
            + 25
            + (65 * (kicker.kick_power / 100.0))
            + (2 * chance_mod)
            + game.kick_mod
            + random_variability())

    min_kick = (35
            + 20
            + (55 * (kicker.kick_power / 100.0))
            + (2 * chance_mod)
            + game.kick_mod
            + random_variability())

    #TODO implement st_mod
    st_mod = 0.0
    return_stat = returner.agility
    if (returner.agility < returner.concentration):
        return_stat = returner.concentration

    min_return = ((0.2 * return_stat + random_variability())
            - st_mod
            + return_mod)

    max_return = ((0.35 * returner.speed + random_variability())
            - st_mod
            + return_mod)

    returns = random_in_range((min_return + return_mod), max_return + return_mod)
    kick = random_in_range((min_kick + chance_mod), (max_kick + chance_mod))

    #TODO if great blocking breakaway

    if kick > 105:
        kick = 105
        if random_chance(kicker.kick_power / 4 + kick_mod):
            back_of_endzone = True
            returns = 0
    elif random_chance((100 - kicker.kick_accuracy) / 2 - kick_mod + 1):
        out_of_bounds = True
        kick = 60
        returns = 0

    if (kick >= 100) and great_blocking is False and random_chance(return_stat - 30):
        returns = 0

    if (kick >= 100) and great_blocking is False and returns < 15:
        returns = 0

    kick_return = kick - returns
    touchback = False
    touchdown = False
    if kick_return > 99:
        kick_return = 80
        tocuhback = True

    if kick_return < 1:
        touchdown = True
        returns = kick
        kick_return = 0

    if touchback is False and out_of_bounds is False:
        log_kr = True
        #TODO log KR to returner

    game.yard_line = 100 - kick_return

    if touchback:
        log_tb = True
        #TODO log touchback to kicker

    if touchdown:
        game.defense.score += 6
        game = spend_time(10, 20, 10, False)
        game = execute_turnover(game)
        if game.overtime is False:
            return execute_extra_point(game)

    #TODO clean up post kickoff possession change logic

    return game
Пример #9
0
def determine_completion_chance(game, play_mod):
    """
    Return the chance of pass completion from passed game state
    """
    chance_mod = random.randint(-3, 3)

    chance = (27.5
              + (30.0 * (game.offense.get_player('QB', 1).throw_accuracy / 100.0))
              + (2.5 * (game.offense.get_player('QB', 1).throw_power / 100.0))
              + (20.0 * (game.offense.pass_blocking / 100.0))
              + (2.5 * (game.offense.get_player('TE', 1).run_blocking / 100.0))
              + (2.5 * (game.offense.get_player('FB', 1).run_blocking / 100.0))
              + (4.5 * (game.offense.get_player('TE', 1).catching / 100.0))
              + (0.5 * (game.offense.get_player('WR', 1).concentration / 100.0))
              + (0.5 * (game.offense.get_player('WR', 2).concentration / 100.0))
              + (0.5 * (game.offense.get_player('WR', 3).concentration / 100.0))
              + (4.0 * (game.offense.get_player('WR', 1).acceleration / 100.0))
              + (4.0 * (game.offense.get_player('WR', 2).acceleration / 100.0))
              + (4.0 * (game.offense.get_player('WR', 3).acceleration / 100.0))
              + (6.0 * (game.offense.get_player('WR', 1).catching / 100.0))
              + (6.0 * (game.offense.get_player('WR', 2).catching / 100.0))
              + (6.0 * (game.offense.get_player('WR', 3).catching / 100.0))
              + (0.5 * (game.offense.get_player('RB', 1).catching / 100.0))
              + (0.5 * (game.offense.get_player('RB', 2).catching / 100.0))
              + (0.05 * (game.offense.get_player('FB', 1).catching / 100.0))
              - (8.5 * (game.defense.get_player('LCB', 1).coverage / 100.0))
              - (8.5 * (game.defense.get_player('RCB', 1).coverage / 100.0))
              - (7.0 * (game.defense.get_player('SS', 1).coverage / 100.0))
              - (7.0 * (game.defense.get_player('FS', 1).coverage / 100.0))
              + (0.5 * (game.offense.get_player('QB', 1).speed / 100.0))
              + (2.0 * (game.offense.get_player('QB', 1).concentration / 100.0))
              + (3.0 * play_mod)
              + (0.25 * (game.offense.team_mod - game.defense.team_mod))
              + (1.0 * game.pass_mod)
              - (1.25 * (100 - game.defense.drun) / 100.0)
              + (1.0 * ((100.0 - game.offense.gameplan.o_aggression) / 100.0))
              - (1.0 * ((100.0 - game.defense.gameplan.d_aggression) / 100.0))
              + chance_mod
              + random_variability())

    if game.defense.style is '43':
        chance += (0
                   - (20.0 * (game.defense.pass_rush / 100.0))
                   - (2.5 * (game.defense.get_player('LOLB', 1).pass_rush / 100.0))
                   - (2.5 * (game.defense.get_player('MLB', 1).pass_rush / 100.0))
                   - (2.5 * (game.defense.get_player('ROLB', 1).pass_rush / 100.0))
                   - (2.0 * (game.defense.get_player('LOLB', 1).coverage / 100.0))
                   - (2.0 * (game.defense.get_player('MLB', 1).coverage / 100.0))
                   - (2.0 * (game.defense.get_player('ROLB', 1).coverage / 100.0)))
    else:
        chance += (0
                   - (6.5 *  (game.defense.pass_rush / 100.0))
                   - (4.75 * (game.defense.get_player('LOLB', 1).pass_rush / 100.0))
                   - (4.75 * (game.defense.get_player('LILB', 1).pass_rush / 100.0))
                   - (4.75 * (game.defense.get_player('RILB', 1).pass_rush / 100.0))
                   - (4.75 * (game.defense.get_player('ROLB', 1).pass_rush / 100.0))
                   - (2.0 * (game.defense.get_player('LOLB', 1).coverage / 100.0))
                   - (2.0 * (game.defense.get_player('LILB', 1).coverage / 100.0))
                   - (2.0 * (game.defense.get_player('RILB', 1).coverage / 100.0))
                   - (2.0 * (game.defense.get_player('ROLB', 1).coverage / 100.0)))

    while (chance < 60) and not random_chance(game.defense.get_player('RCB', 1).coverage + 1) \
            and not random_chance(game.defense.get_player('FS', 1) + 1):
        chance += 0.25
        if chance > 60:
            chance = 60

    if chance < 52:
        chance += (52 - chance) / 1.5

    if chance > 62:
        chance += (chance - 62) / 1.5

    if game.yard_line <= 10:
        chance -= 3

    return chance