Advertisement
dougbaker45

football_1.0

Aug 25th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 28.33 KB | None | 0 0
  1. import random
  2. from timeit import default_timer as timer
  3. start = timer()
  4. hometeam = 'New England Patriots'
  5. awayteam = 'Arizona Cardinals'
  6. finalscores = []
  7. matchcount = 1
  8. totalpenaltyyards = 0
  9. def statsreset():
  10.     global gamesplayed
  11.     global offset
  12.     global games
  13.     global gametime
  14.     global playtime
  15.     global possession
  16.     global ballposition
  17.     global down
  18.     global seriesyards
  19.     global awayteamscores
  20.     global hometeamscores
  21.     global totalstats
  22.     global totalscores
  23.     global atstats
  24.     global htstats
  25.     global interceptionhappened
  26.     offset = 1000
  27.     games = 0
  28.     gametime = 60
  29.     playtime = .4
  30.     possession = None
  31.     ballposition = 0
  32.     down = 0
  33.     seriesyards = 0
  34.     awayteamscores = 0
  35.     hometeamscores = 0
  36.     interceptionhappened = 'no'
  37.     scores = {hometeam:0, awayteam:0}
  38.     totalscores = {hometeam:0, awayteam:0}
  39.     totalstats = {'totalrunplays':0, 'totalpassplays':0, 'totalpuntplays':0, 'totalfieldgoalplays':0, 'totalrushyards':0, 'totalpassyards':0, 'totalpuntyards':0, 'totalcompletions':0, 'cointosswinner '+str(hometeam):0, 'cointosswinner '+str(awayteam):0}
  40.     htstats = {'totalrunplays':0, 'totalpassplays':0, 'totalpuntplays':0, 'totalfieldgoalplays':0, 'totalrushyards':0, 'totalpassyards':0, 'totalpuntyards':0, 'totalcompletions':0, 'cointosswinner '+str(hometeam):0}
  41.     atstats = {'totalrunplays':0, 'totalpassplays':0, 'totalpuntplays':0, 'totalfieldgoalplays':0, 'totalrushyards':0, 'totalpassyards':0, 'totalpuntyards':0, 'totalcompletions':0, 'cointosswinner '+str(awayteam):0}
  42.  
  43.  
  44. def teamstats():
  45.     global possession
  46.     import csv
  47.     global htoffense
  48.     global atoffense
  49.     global htdefense
  50.     global atdefense
  51.     global htKicking_Punting
  52.     global atKicking_Punting
  53.     global htreturning
  54.     global atreturning
  55.  
  56.     if possession == hometeam:
  57.         nonpossession = awayteam
  58.     else: nonpossession = hometeam
  59.  
  60.     with open('offense.csv', newline='') as csvfile:
  61.          offenses = csv.DictReader(csvfile)
  62.          for row in offenses:
  63.              #print(row)
  64.              if row['Tm'] == hometeam:
  65.                 htoffense = row
  66.              if row['Tm'] == awayteam:
  67.                 atoffense = row
  68.  
  69.     with open('defense.csv', newline='') as csvfile:
  70.          defenses = csv.DictReader(csvfile)
  71.          for row in defenses:
  72.              #print(row)
  73.              if row['Tm'] == hometeam:
  74.                  htdefense = row
  75.              if row['Tm'] == awayteam:
  76.                  atdefense = row
  77.  
  78.     with open('Kicking_Punting.csv', newline='') as csvfile:
  79.          Kicking_Punting = csv.DictReader(csvfile)
  80.          for row in Kicking_Punting:
  81.              #print(row)
  82.              if row['Tm'] == hometeam:
  83.                  htKicking_Punting = row
  84.              if row['Tm'] == awayteam:
  85.                  atKicking_Punting = row
  86.  
  87.     with open('returning.csv', newline='') as csvfile:
  88.          returning = csv.DictReader(csvfile)
  89.          for row in returning:
  90.              #print(row)
  91.              if row['Tm'] == hometeam:
  92.                  htreturning = row
  93.              if row['Tm'] == awayteam:
  94.                  atreturning = row
  95.     #print(htKicking_Punting)
  96.     #print(atKicking_Punting)
  97.     #print(htreturning)
  98.     #print(atreturning)
  99. def cointoss():
  100.     global gametime
  101.     global possession
  102.     global halftimepossession
  103.     global scores
  104.     gametime = 60
  105.     scores = {hometeam:0, awayteam:0}
  106.     cointossresult = random.randint(1, 2)
  107.     if cointossresult == 1:
  108.         possession = hometeam
  109.         halftimepossession = awayteam
  110.         totalstats['cointosswinner '+str(awayteam)] += 1
  111.         atstats['cointosswinner '+str(awayteam)] += 1
  112.     else:
  113.         possession = awayteam
  114.         halftimepossession = hometeam
  115.         totalstats['cointosswinner '+str(hometeam)] += 1
  116.         htstats['cointosswinner '+str(hometeam)] += 1
  117.     #print('cointoss winner', halftimepossession)
  118.  
  119. def halftime():
  120.     global possession
  121.     global halftimepossession
  122.     global scores
  123.     global ballposition
  124.     #print(ballposition)
  125.     #print(gametime)
  126.     if ballposition >= 4000:
  127.         fieldgoalplayexecute()
  128.     possession = halftimepossession
  129.     #print('')
  130.     #print('')
  131.     #print('halftime')
  132.     kickoff()
  133.  
  134. def kickoff():
  135.     global ballposition
  136.     global gametime
  137.     global possession
  138.     global down
  139.     ballposition = 0
  140.     returnteam = possession
  141.     kickofftd = random.randint(1, 100)
  142.     gametime -= random.uniform(.2, .6)
  143.     if kickofftd <= 1:
  144.         scores[returnteam] += 6
  145.         extrapointexecute()
  146.         turnover()
  147.         kickoff()
  148.     else:
  149.         if possession == hometeam:
  150.             ballposition = float(htreturning['Kick Returns Y/Rt']) * 97
  151.             #print(hometeam, 'kickoff returned to :', ballposition)
  152.         if possession == awayteam:
  153.             ballposition = float(atreturning['Kick Returns Y/Rt']) * 97
  154.             #print(awayteam, 'kickoff returned to :', ballposition)
  155.         down = 1
  156.         kickoffbigplay = random.randint(1, 100)
  157.         if kickoffbigplay <= 4:
  158.             ballposition += random.randint(1, 2500)
  159.             #print('Kickoff big play!', kickoffbigplay)
  160.             #print('ballposition', ballposition)
  161.     #print('ballposition', ballposition)
  162.     #print('gametime', gametime)
  163.  
  164. def chooseplay():
  165.     global possession
  166.     global down
  167.     global playchoice
  168.     global ballposition
  169.     offense = possession
  170.     #print(htoffense['Rushing Att'])
  171.     #print((100 * (int(atoffense['Rushing Att']) / int(atoffense['Tot Ply']))))
  172.     if possession == hometeam:
  173.         if down < 4:
  174.             playodds = random.randint(1, 100)
  175.             #print('playodds', playodds, 'play num', int((100 * (int(htoffense['Rushing Att']) / int(htoffense['Tot Ply'])))))
  176.             if playodds >= (int((100 * (int(htoffense['Rushing Att']) / int(htoffense['Tot Ply']))))):
  177.                 playchoice = 'passplay'
  178.             else:
  179.                 playchoice = 'runplay'
  180.         else:
  181.             if ballposition > 5300:
  182.                 playchoice = 'fieldgoalplay'
  183.             else:
  184.                 playchoice = 'puntplay'
  185.         #print(playchoice)
  186.     if possession == awayteam:
  187.         if down < 4:
  188.             playodds = random.randint(1, 100)
  189.             #print('playodds', playodds, 'play  num', int((100 * (int(atoffense['Rushing Att']) / int(atoffense['Tot Ply'])))))
  190.             if playodds >= (int((100 * (int(atoffense['Rushing Att']) / int(atoffense['Tot Ply']))))):
  191.                 playchoice = 'passplay'
  192.             else:
  193.                 playchoice = 'runplay'
  194.         else:
  195.             if ballposition > 5300:
  196.                 playchoice = 'fieldgoalplay'
  197.             else:
  198.                 playchoice = 'puntplay'
  199.         #print(playchoice)
  200.  
  201.  
  202. def passplayexecute():
  203.     global possession
  204.     global ballposition
  205.     global down
  206.     global seriesyards
  207.     global totalstats
  208.     global htstats
  209.     global atstats
  210.     global interceptionhappened
  211.     totalstats['totalpassplays'] += 1
  212.     completionchace = random.randint(1,100)
  213.     #print(possession)
  214.     if possession == hometeam:
  215.         htstats['totalpassplays'] += 1
  216.         #print('completionchace', completionchace, 'Max Odds', 100 *(((int(htoffense['Passing Cmp']) / int(htoffense['Passing Att']))  + (int(atdefense['Passing Cmp']) / int(atdefense['Passing Att']))) / 2))
  217.         if completionchace <= int(100 * (((int(htoffense['Passing Cmp']) / int(htoffense['Passing Att']))  + (int(atdefense['Passing Cmp']) / int(atdefense['Passing Att']))) / 2)):
  218.             passcomplete = 'complete'
  219.         else:
  220.             passcomplete = 'incomplete'
  221.     if possession == awayteam:
  222.         atstats['totalpassplays'] += 1
  223.         #print('completionchace', completionchace, 'Max odds', 100 *(((int(htoffense['Passing Cmp']) / int(htoffense['Passing Att']))  + (int(atdefense['Passing Cmp']) / int(atdefense['Passing Att']))) / 2))
  224.         if completionchace <= int(100 * (((int(atoffense['Passing Cmp']) / int(atoffense['Passing Att']))  + (int(htdefense['Passing Cmp']) / int(htdefense['Passing Att']))) / 2)):
  225.             passcomplete = 'complete'
  226.         else:
  227.             passcomplete = 'incomplete'
  228.     if passcomplete == 'complete':
  229.         #print('Pass complete')
  230.         totalstats['totalcompletions'] += 1
  231.         down += 1
  232.         if possession == hometeam:
  233.             htstats['totalcompletions'] += 1
  234.             passmod = (100 * ((int(htoffense['Passing Yds']) / int(htoffense['Passing Cmp'])) + (int(atdefense['Passing Yds']) / int(atdefense['Passing Cmp']))) / 2)
  235.             #print('[passmod]', passmod)
  236.             passyards = passmod + random.uniform(-(passmod + 200), passmod + 200)
  237.             htstats['totalpassyards'] += passyards
  238.         if possession == awayteam:
  239.             atstats['totalcompletions'] += 1
  240.             passmod = (100 * ((int(atoffense['Passing Yds']) / int(atoffense['Passing Cmp'])) + (int(htdefense['Passing Yds']) / int(htdefense['Passing Cmp']))) / 2)
  241.             #print('[passmod]', passmod)
  242.             passyards = passmod + random.uniform(-(passmod + 200), passmod + 200)
  243.             atstats['totalpassyards'] += passyards
  244.         totalstats['totalpassyards'] += passyards
  245.         #print('passyards', passyards)
  246.         ballposition += passyards
  247.         seriesyards += passyards
  248.         if ballposition >= 10000:
  249.             scores[possession] += 6
  250.             extrapointexecute()
  251.             #print('passing touchdown')
  252.             #print(scores)
  253.             touchdown = 'yes'
  254.             turnover()
  255.             kickoff()
  256.         if seriesyards >= 1000:
  257.             down = 1
  258.             #print('first down', down)
  259.             seriesyards = 0
  260.             #print('ballposition', ballposition)
  261.             #print('gametime', gametime)
  262.     if passcomplete == 'incomplete':
  263.         down += 1
  264.         #print('incomplete')
  265.  
  266. def runplayexecute():
  267.     global possession
  268.     global ballposition
  269.     global down
  270.     global seriesyards
  271.     global totalstats
  272.     global htstats
  273.     global atstats
  274.     totalstats['totalrunplays'] += 1
  275.     if possession == hometeam:
  276.         nonpossession = awayteam
  277.         htstats['totalrunplays'] += 1
  278.         runmod = ((100 * float(htoffense['Rushing YPC'])) + (100 * float(atdefense['Rushing YPC']))) / 2
  279.         #print(((htoffense['Rushing Y/A']) + (atdefense['Rushing Y/A']) / 2))
  280.         runresult = runmod + random.uniform(-(runmod + 300), (runmod + 300))
  281.         #print('runmod', runmod, 'nrundistance', nrundistance, 'runresult', runresult)
  282.         #print('runresult', runresult)
  283.         htstats['totalrushyards'] += runresult
  284.     if possession == awayteam:
  285.         nonpossession = hometeam
  286.         atstats['totalrunplays'] += 1
  287.         runmod = ((100 * float(htoffense['Rushing YPC'])) + (100 * float(atdefense['Rushing YPC']))) / 2
  288.         #print(((htoffense['Rushing Y/A']) + (atdefense['Rushing Y/A']) / 2))
  289.         runresult = runmod + random.uniform(-(runmod + 300), (runmod + 300))
  290.         #print('runmod', runmod, 'nrundistance', nrundistance, 'runresult', runresult)
  291.         #print('runresult', runresult)
  292.         atstats['totalrushyards'] += runresult
  293.     down += 1
  294.     ballposition += runresult
  295.     seriesyards += runresult
  296.     atstats['totalrushyards'] += 1
  297.     if ballposition >= 10000:
  298.         scores[possession] += 6
  299.         extrapointexecute()
  300.         #print('rushing touchdown')
  301.         #print(scores)
  302.         turnover()
  303.         kickoff()
  304.     if seriesyards >= 1000:
  305.         down = 1
  306.         #print('first down', down)
  307.         seriesyards = 0
  308.         #print('ballposition', ballposition)
  309.     totalstats['totalrushyards'] += runresult
  310.     if ballposition <= 0:
  311.         #print('Safety')
  312.         scores[nonpossession] += 2
  313.         puntplayexecute()
  314.  
  315. def puntplayexecute():
  316.     global ballposition
  317.     global possession
  318.     global ballposition
  319.     global down
  320.     global totalpuntplays
  321.     global totalpuntyards
  322.     totalstats['totalpuntplays'] += 1
  323.     puntyards = 4500 + random.randint(-2000, 2000)
  324.     totalstats['totalpuntyards'] += puntyards
  325.     #print('puntyards', puntyards)
  326.     ballposition += puntyards
  327.     if ballposition >= 10000:
  328.         ballposition = 8000
  329.     turnover()
  330. #### Customize punts
  331. def fieldgoalplayexecute():
  332.     global scores
  333.     global ballposition
  334.     global totalfieldgoalplays
  335.     global possession
  336.     #print('Field goal start')
  337.     #print('ballposition', ballposition)
  338.     ballposition = int(ballposition)
  339.     #print(ballposition)
  340.     totalstats['totalfieldgoalplays'] += 1
  341.     if 4000 <= ballposition <= 4999:
  342.         if possession == hometeam:
  343.             fgmod = ((float(htKicking_Punting['50 FGM']) / float(htKicking_Punting['50 FGA'])) * 100)
  344.             #print('gametime', gametime)
  345.             #print('Field Goal attempt 50+', fgmod)
  346.         if possession == awayteam:
  347.             fgmod = ((float(htKicking_Punting['50 FGM']) / float(htKicking_Punting['50 FGA'])) * 100)
  348.             #print('Field Goal attempt 50+', fgmod)
  349.             #print('gametime', gametime)
  350.     if 5000 <= ballposition <= 5999:
  351.         if possession == hometeam:
  352.             fgmod = ((float(htKicking_Punting['40-49 FGM']) / float(htKicking_Punting['40-49 FGA'])) * 100)
  353.             #print('Field Goal attempt 40-49', fgmod)
  354.             #print('gametime', gametime)
  355.         if possession == awayteam:
  356.             fgmod = ((float(htKicking_Punting['40-49 FGM']) / float(htKicking_Punting['40-49 FGA'])) * 100)
  357.             #print('Field Goal attempt 40-49', fgmod)
  358.             #print('gametime', gametime)
  359.     if 6000 <= ballposition <= 6999:
  360.         if possession == hometeam:
  361.             fgmod =((float(htKicking_Punting['30-39 FGM']) / float(htKicking_Punting['30-39 FGA'])) * 100)
  362.             #print('Field Goal attempt 30-39', fgmod)
  363.             #print('gametime', gametime)
  364.         if possession == awayteam:
  365.             fgmod = ((float(htKicking_Punting['30-39 FGM']) / float(htKicking_Punting['30-39 FGA'])) * 100)
  366.             #print('Field Goal attempt 30-39', fgmod)
  367.             #print('gametime', gametime)
  368.     if 7000 <= ballposition <= 7999:
  369.         if possession == hometeam:
  370.             fgmod = (float(htKicking_Punting['20-29 FGM']) / float(htKicking_Punting['20-29 FGA'])) * 100
  371.             #print('Field Goal attempt 20-29', fgmod)
  372.             #print('gametime', gametime)
  373.         if possession == awayteam:
  374.             fgmod = (float(htKicking_Punting['20-29 FGM']) / float(htKicking_Punting['20-29 FGA'])) * 100
  375.             #print('Field Goal attempt 20-29', fgmod)
  376.             #print('gametime', gametime)
  377.     if ballposition >= 8000:
  378.         fgmod = 99
  379.         #print('Field Goal attempt 0-19', fgmod)
  380.         #print('gametime', gametime)
  381.     fgchance = random.randint(0, 100)
  382.     if fgchance <= fgmod:
  383.         scores[possession] += 3
  384.         #print('fieldgoal made')
  385.         turnover()
  386.         kickoff()
  387.     else:
  388.         turnover()
  389.  
  390. def extrapointexecute():
  391.     global scores
  392.     if possession == hometeam:
  393.         xpmod = float(htKicking_Punting['Scoring XP%'])
  394.     if possession == awayteam:
  395.         xpmod = float(atKicking_Punting['Scoring XP%'])
  396.     xpchance = random.randint(0, 100)
  397.     #print('xp', xpmod, xpchance)
  398.     if xpchance <= xpmod:
  399.         scores[possession] += 1
  400.  
  401. def interceptioncheck():
  402.     global possession
  403.     global hometeam
  404.     global awayteam
  405.     global ballposition
  406.     global playchoice
  407.     interceptionchance = random.randint(0, 100)
  408.     if possession == hometeam:
  409.         interceptionodds = (((float(htoffense['Int']) / float(htoffense['Passing Att'])) + (float(atdefense['Passing Int']) / float(atdefense['Passing Att'])) / 2) * 100)
  410.         #print('interceptionodds', interceptionodds, 'interceptionchance', interceptionchance)
  411.         nonpossession = awayteam
  412.     if possession == awayteam:
  413.         interceptionodds = (((float(atoffense['Int']) / float(atoffense['Passing Att'])) + (float(htdefense['Passing Int']) / float(htdefense['Passing Att'])) / 2) * 100)
  414.         #print('interceptionodds', interceptionodds, 'interceptionchance', interceptionchance)
  415.         nonpossession = hometeam
  416.     if interceptionodds >= interceptionchance:
  417.         playchoice = 'interception happened'
  418.         #print(' ')
  419.         #print(' ')
  420.         #print(' ')
  421.         #print(' ')
  422.         #print('Interception! ', nonpossession, ' intercepts the ball from', possession)
  423.         pick6chance = random.randint(0, 100)
  424.         if pick6chance >= 99:
  425.             #print('Interception! ', nonpossession, ' intercepts the ball from', possession)
  426.             #print('Pick 6!')
  427.             #print(scores)
  428.             scores[nonpossession] += 6
  429.             #print(scores)
  430.             #print(possession, 'posession pre turnover')
  431.             turnover()
  432.             #print(possession, 'posession post turnover')
  433.             extrapointexecute()
  434.             #print(possession, 'posession post extra point')
  435.             #print(scores)
  436.             turnover()
  437.             #print(possession, 'posession post second turnover')
  438.             kickoff()
  439.             #print(possession, 'posession post kickoff')
  440.         else:
  441.             turnover()
  442.  
  443. def fumblecheck():
  444.     global possession
  445.     global hometeam
  446.     global awayteam
  447.     global ballposition
  448.     global playchoice
  449.     fumblechance = random.randint(0, 100)
  450.     if possession == hometeam:
  451.         fumbleodds = (((float(htoffense['FL']) / float(htoffense['Rushing Att'])) + (float(atdefense['FL']) / float(atdefense['Rushing  Att'])) / 2) * 100)
  452.         #print('fumbleodds', fumbleodds, 'fumblechance', fumblechance)
  453.         nonpossession = awayteam
  454.     if possession == awayteam:
  455.         fumbleodds = (((float(atoffense['FL']) / float(atoffense['Rushing Att'])) + (float(htdefense['FL']) / float(htdefense['Rushing  Att'])) / 2) * 100)
  456.         #print('fumbleodds', fumbleodds, 'fumblechance', fumblechance)
  457.         nonpossession = hometeam
  458.     if fumbleodds >= fumblechance:
  459.         playchoice = 'fumble happened'
  460.         #print(' ')
  461.         #print(' ')
  462.         #print(' ')
  463.         #print(' ')
  464.         #print('Fumble! ', nonpossession, ' recovers the ball from', possession)
  465.         fumble6chance = random.randint(0, 100)
  466.         if fumble6chance >= 99:
  467.             #print('Fumble 6!')
  468.             #print('Fumble! ', nonpossession, ' recovers the ball from', possession)
  469.             #print(scores)
  470.             scores[nonpossession] += 6
  471.             #print(scores)
  472.             turnover()
  473.             extrapointexecute()
  474.             #print(scores)
  475.             kickoff()
  476.         else:
  477.             turnover()
  478.  
  479. def penaltycheck():
  480.     global possession
  481.     global seriesyards
  482.     global ballposition
  483.     global down
  484.     global gametime
  485.     global totalpenaltyyards
  486.     global scores
  487.     global playchoice
  488.     offensepenaltychance = random.randint(0, 100)
  489.     defensepenaltychance = random.randint(0, 100)
  490.  
  491.     if possession == hometeam:
  492.         offensepenaltyodds = ((float(htoffense['Pen Ct']) / float(htoffense['Tot Ply'])) * 100)
  493.         offensepenaltyyards = ((float(htoffense['Pen Yds']) / float(htoffense['Pen Ct'])) * 100)
  494.         defensepenaltyodds = ((float(atdefense['Pen Ct']) / float(atdefense['Ply'])) * 100)
  495.         defensepenaltyyards = ((float(atdefense['Pen Yds']) / float(atdefense['Pen Ct'])) * 100)
  496.         if offensepenaltychance <= offensepenaltyodds:
  497.             gametime -= random.uniform(.2, .6)
  498.             #print(possession, offensepenaltyodds, ' | ', 'offensepenaltyyards', offensepenaltyyards)
  499.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  500.             ballposition -= offensepenaltyyards
  501.             seriesyards -= offensepenaltyyards
  502.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  503.             totalpenaltyyards += offensepenaltyyards
  504.             playchoice = 'penaltyhappened'
  505. #### Need to implement safety
  506.         if defensepenaltychance <= defensepenaltyodds:
  507.             gametime -= random.uniform(.2, .6)
  508.             #print(possession, defensepenaltyyards,'defpenaltyyards', ' | ', 'defensepenaltyodds', defensepenaltyodds)
  509.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  510.             ballposition += offensepenaltyyards
  511.             seriesyards += offensepenaltyyards
  512.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  513.             totalpenaltyyards += offensepenaltyyards
  514.             playchoice = 'penaltyhappened'
  515.  
  516.     if possession == awayteam:
  517.         offensepenaltyodds = ((float(atoffense['Pen Ct']) / float(atoffense['Tot Ply'])) * 100)
  518.         offensepenaltyyards = ((float(atoffense['Pen Yds']) / float(atoffense['Pen Ct'])) * 100)
  519.         defensepenaltyodds = ((float(htdefense['Pen Ct']) / float(htdefense['Ply'])) * 100)
  520.         defensepenaltyyards = ((float(htdefense['Pen Yds']) / float(htdefense['Pen Ct'])) * 100)
  521.         if offensepenaltychance <= offensepenaltyodds:
  522.             gametime -= random.uniform(.2, .6)
  523.             #print(possession, offensepenaltyodds, ' | ', 'offensepenaltyyards', offensepenaltyyards)
  524.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  525.             ballposition -= offensepenaltyyards
  526.             seriesyards -= offensepenaltyyards
  527.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  528.             totalpenaltyyards += offensepenaltyyards
  529.             playchoice = 'penaltyhappened'
  530.         if defensepenaltychance <= defensepenaltyodds:
  531.             gametime -= random.uniform(.2, .6)
  532.             #print(possession, defensepenaltyyards,'defpenaltyyards', ' | ', 'defensepenaltyodds', defensepenaltyodds)
  533.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  534.             ballposition += offensepenaltyyards
  535.             seriesyards += offensepenaltyyards
  536.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  537.             totalpenaltyyards += offensepenaltyyards
  538.             playchoice = 'penaltyhappened'
  539.  
  540.     if seriesyards >= 1000:
  541.         down = 1
  542.         #print('first down', down)
  543.         seriesyards = 0
  544.         #print('ballposition', ballposition)
  545.  
  546. def sackcheck():
  547.     global posession
  548.     global playchoice
  549.     global down
  550.     global ballposition
  551.     global seriesyards
  552.     global scores
  553.     sackchance = random.randint(0, 100)
  554.     if possession == hometeam:
  555.         nonpossession = awayteam
  556.         sackodds = ((((float(htoffense['Sk']) / float(htoffense['Passing Att'])) * 100) + ((float(atdefense['Sk']) / float(atdefense['Passing Att'])) * 100)) / 2)
  557.         sackyards = ((((float(htoffense['Sk Yds']) / float(htoffense['Sk'])) * 100) + ((float(atdefense['Sk Yds']) / float(atdefense['Sk'])) * 100)) / 2)
  558.     if possession == awayteam:
  559.         nonpossession = hometeam
  560.         sackodds = ((((float(atoffense['Sk']) / float(atoffense['Passing Att'])) * 100) + ((float(htdefense['Sk']) / float(htdefense['Passing Att'])) * 100)) / 2)
  561.         sackyards = ((((float(atoffense['Sk Yds']) / float(atoffense['Sk'])) * 100) + ((float(htdefense['Sk Yds']) / float(htdefense['Sk'])) * 100)) / 2)
  562.     if sackchance <= sackodds:
  563.         playchoice = 'sackhappened'
  564.         ballposition -= sackyards
  565.         seriesyards -= sackyards
  566.         down += 1
  567.         if ballposition <= 0:
  568.             #print('Safety')
  569.             scores[nonpossession] += 2
  570.             puntplayexecute()
  571.  
  572. def turnover():
  573.     global down
  574.     global ballposition
  575.     global possession
  576.     global seriesyards
  577.     down = 1
  578.     ballposition = abs(ballposition - 1000)
  579.     if possession == hometeam:
  580.         possession = awayteam
  581.     else:
  582.         possession = hometeam
  583.     seriesyards = 0
  584.     #print('possession', possession)
  585.     #print('ballposition', ballposition)
  586.     #print('gametime', gametime)
  587.  
  588. def executeplay():
  589.     global playchoice
  590.     global gametime
  591.     gametime -= random.uniform(.2, .6)
  592.     penaltycheck()
  593.     if playchoice == 'runplay':
  594.         fumblecheck()
  595.     if playchoice == 'runplay':
  596.         runplayexecute()
  597.     if playchoice == 'passplay':
  598.         sackcheck()
  599.     if playchoice == 'passplay':
  600.         interceptioncheck()
  601.     if playchoice == 'passplay':
  602.         passplayexecute()
  603.     if playchoice == 'fieldgoalplay':
  604.         fieldgoalplayexecute()
  605.     if playchoice == 'puntplay':
  606.         puntplayexecute()
  607.     #print(playchoice)
  608.     #print(playchoice, possession)
  609.  
  610. def game():
  611.     teamstats()
  612.     cointoss()
  613.     kickoff()
  614.     while gametime >= 30:
  615.         chooseplay()
  616.         executeplay()
  617.     halftime()
  618.     while gametime >= 0:
  619.         chooseplay()
  620.         executeplay()
  621.     #print('scores: ', scores)
  622.     #print('gametime Over')
  623.     global wins
  624.     winner = max(scores.keys(), key=(lambda k: scores[k]))
  625.     #print('winner :', winner)
  626.     global totalscores
  627.     hometeamscores = scores[hometeam]
  628.     awayteamscores = scores[awayteam]
  629.     totalscores[hometeam] += hometeamscores
  630.     totalscores[awayteam] += awayteamscores
  631.     global end
  632.  
  633. def printstats():
  634.     global totalpassplays
  635.     global totalpassyards
  636.     global totalcompletions
  637.     global end
  638.     global start
  639.     global gamesplayed
  640.     global finalscores
  641.     global matchcount
  642.     #print('Total Scores: ', totalscores)
  643.     #print('Total Yards per attempt: ', (totalstats['totalpassyards'] / totalstats['totalpassplays']) / 100)
  644.     #print('Total Average yards per completion', (totalstats['totalpassyards'] / totalstats['totalcompletions']) / 100)
  645.     #print('Total per Carry: ', (totalstats['totalrushyards'] / totalstats['totalrunplays']) / 100)
  646.     #print('Total yards per punt: ', (totalstats['totalpuntyards'] / totalstats['totalpuntplays']) / 100)
  647.     htstats['comp percent'] = 100 * (htstats['totalcompletions'] / htstats['totalpassplays'])
  648.     htstats['YP COMP'] = (htstats['totalpassyards'] / htstats['totalcompletions']) / 100
  649.     htstats['YP Carry'] = (htstats['totalrushyards'] / htstats['totalrunplays']) / 100
  650.     atstats['comp percent'] = 100 * (atstats['totalcompletions'] / atstats['totalpassplays'])
  651.     atstats['YP COMP'] = (atstats['totalpassyards'] / atstats['totalcompletions']) / 100
  652.     atstats['YP Carry'] = (atstats['totalrushyards'] / atstats['totalrunplays']) / 100
  653.     #print(hometeam, htstats)
  654.     #print(awayteam, atstats)
  655.     #print(hometeam,'completion %: ', htstats['comp percent'],' Yards Per completion: ', htstats['YP COMP'],'Yards Per Carry: ', htstats['YP Carry'] )
  656.     #print(awayteam,'completion %: ', atstats['comp percent'],' Yards Per completion: ', atstats['YP COMP'],'Yards Per Carry: ', atstats['YP Carry'] )
  657.     #print('Average scores :', hometeam, (totalscores[hometeam] / gamesplayed), awayteam, (totalscores[awayteam] / gamesplayed))
  658.     end = timer()
  659.     #print('time: ', (end - start) )
  660.     #print('')
  661.     finalscores.append(hometeam + ' : ' + str((totalscores[hometeam] / gamesplayed)) + ' | ' + awayteam + ' : ' + str((totalscores[awayteam] / gamesplayed)))
  662.  
  663.  
  664. def match():
  665.     global games
  666.     global offset
  667.     global gamesplayed
  668.     global matchcount
  669.     global totalpenaltyyards
  670.     statsreset()
  671.     for i in range(gamesplayed):
  672.         game()
  673.         games += 1
  674.         if games >= offset:
  675.             print('Percent complete: ', int(( 100 * (offset / gamesplayed))), ' | Match Number: ', matchcount)
  676.             offset += 10000
  677.     matchcount += 1
  678.     printstats()
  679.     #print(totalpenaltyyards)
  680.  
  681. gamesplayed = 16
  682. hometeam = 'Philadelphia Eagles'
  683. awayteam = 'New York Giants'
  684. match()
  685.  
  686. hometeam = 'Seattle Seahawks'
  687. awayteam = 'Oakland Raiders'
  688. match()
  689.  
  690. hometeam = 'Los Angeles Chargers'
  691. awayteam = 'Cleveland Browns'
  692. match()
  693.  
  694. hometeam = 'Tampa Bay Buccaneers'
  695. awayteam = 'Atlanta Falcons'
  696. match()
  697.  
  698. hometeam = 'Buffalo Bills'
  699. awayteam = 'Houston Texans'
  700. match()
  701.  
  702. hometeam = 'Carolina Panthers'
  703. awayteam = 'Washington Redskins'
  704. match()
  705.  
  706. hometeam = 'Baltimore Ravens'
  707. awayteam = 'Tennessee Titans'
  708. match()
  709.  
  710. hometeam = 'Kansas City Chiefs'
  711. awayteam = 'New England Patriots'
  712. match()
  713.  
  714. hometeam = 'Indianapolis Colts'
  715. awayteam = 'New York Jets'
  716. match()
  717.  
  718. hometeam = 'Chicago Bears'
  719. awayteam = 'Miami Dolphins'
  720. match()
  721.  
  722. hometeam = 'Arizona Cardinals'
  723. awayteam = 'Minnesota Vikings'
  724. match()
  725.  
  726. hometeam = 'Pittsburgh Steelers'
  727. awayteam = 'Cincinnati Bengals'
  728. match()
  729.  
  730. hometeam = 'Los Angeles Rams'
  731. awayteam = 'Denver Broncos'
  732. match()
  733.  
  734. hometeam = 'Jacksonville Jaguars'
  735. awayteam = 'Dallas Cowboys'
  736. match()
  737.  
  738. hometeam = 'San Francisco 49ers'
  739. awayteam = 'Green Bay Packers'
  740. match()
  741.  
  742. #hometeam = 'Detroit Lions'
  743. #awayteam = 'Green Bay Packers'
  744. #match()
  745. print(finalscores)
  746. print('time: ', (end - start) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement