Advertisement
dougbaker45

football_0.99

Aug 25th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 26.44 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.     interceptioncheck()
  215.     if possession == hometeam:
  216.         htstats['totalpassplays'] += 1
  217.         #print('completionchace', completionchace, 'Max Odds', 100 *(((int(htoffense['Passing Cmp']) / int(htoffense['Passing Att']))  + (int(atdefense['Passing Cmp']) / int(atdefense['Passing Att']))) / 2))
  218.         if completionchace <= int(100 * (((int(htoffense['Passing Cmp']) / int(htoffense['Passing Att']))  + (int(atdefense['Passing Cmp']) / int(atdefense['Passing Att']))) / 2)):
  219.             passcomplete = 'complete'
  220.         else:
  221.             passcomplete = 'incomplete'
  222.     if possession == awayteam:
  223.         atstats['totalpassplays'] += 1
  224.         #print('completionchace', completionchace, 'Max odds', 100 *(((int(htoffense['Passing Cmp']) / int(htoffense['Passing Att']))  + (int(atdefense['Passing Cmp']) / int(atdefense['Passing Att']))) / 2))
  225.         if completionchace <= int(100 * (((int(atoffense['Passing Cmp']) / int(atoffense['Passing Att']))  + (int(htdefense['Passing Cmp']) / int(htdefense['Passing Att']))) / 2)):
  226.             passcomplete = 'complete'
  227.         else:
  228.             passcomplete = 'incomplete'
  229.     if passcomplete == 'complete':
  230.         #print('Pass complete')
  231.         totalstats['totalcompletions'] += 1
  232.         down += 1
  233.         if possession == hometeam:
  234.             htstats['totalcompletions'] += 1
  235.             passmod = (100 * ((int(htoffense['Passing Yds']) / int(htoffense['Passing Cmp'])) + (int(atdefense['Passing Yds']) / int(atdefense['Passing Cmp']))) / 2)
  236.             #print('[passmod]', passmod)
  237.             passyards = passmod + random.uniform(-(passmod + 200), passmod + 200)
  238.             htstats['totalpassyards'] += passyards
  239.         if possession == awayteam:
  240.             atstats['totalcompletions'] += 1
  241.             passmod = (100 * ((int(atoffense['Passing Yds']) / int(atoffense['Passing Cmp'])) + (int(htdefense['Passing Yds']) / int(htdefense['Passing Cmp']))) / 2)
  242.             #print('[passmod]', passmod)
  243.             passyards = passmod + random.uniform(-(passmod + 200), passmod + 200)
  244.             atstats['totalpassyards'] += passyards
  245.         totalstats['totalpassyards'] += passyards
  246.         #print('passyards', passyards)
  247.         ballposition += passyards
  248.         seriesyards += passyards
  249.         if ballposition >= 10000:
  250.             scores[possession] += 6
  251.             extrapointexecute()
  252.             #print('passing touchdown')
  253.             #print(scores)
  254.             touchdown = 'yes'
  255.             turnover()
  256.             kickoff()
  257.         if seriesyards >= 1000:
  258.             down = 1
  259.             #print('first down', down)
  260.             seriesyards = 0
  261.             #print('ballposition', ballposition)
  262.             #print('gametime', gametime)
  263.     if passcomplete == 'incomplete':
  264.         down += 1
  265.         #print('incomplete')
  266.  
  267. def runplayexecute():
  268.     global possession
  269.     global ballposition
  270.     global down
  271.     global seriesyards
  272.     global totalstats
  273.     global htstats
  274.     global atstats
  275.     totalstats['totalrunplays'] += 1
  276.     fumblecheck()
  277.     if possession == hometeam:
  278.         htstats['totalrunplays'] += 1
  279.         runmod = ((100 * float(htoffense['Rushing YPC'])) + (100 * float(atdefense['Rushing YPC']))) / 2
  280.         #print(((htoffense['Rushing Y/A']) + (atdefense['Rushing Y/A']) / 2))
  281.         runresult = runmod + random.uniform(-(runmod + 300), (runmod + 300))
  282.         #print('runmod', runmod, 'nrundistance', nrundistance, 'runresult', runresult)
  283.         #print('runresult', runresult)
  284.         htstats['totalrushyards'] += runresult
  285.     if possession == awayteam:
  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.  
  311. def puntplayexecute():
  312.     global ballposition
  313.     global possession
  314.     global ballposition
  315.     global down
  316.     global totalpuntplays
  317.     global totalpuntyards
  318.     totalstats['totalpuntplays'] += 1
  319.     puntyards = 4500 + random.randint(-2000, 2000)
  320.     totalstats['totalpuntyards'] += puntyards
  321.     #print('puntyards', puntyards)
  322.     ballposition += puntyards
  323.     if ballposition >= 10000:
  324.         ballposition = 8000
  325.     turnover()
  326.  
  327. def fieldgoalplayexecute():
  328.     global scores
  329.     global ballposition
  330.     global totalfieldgoalplays
  331.     global possession
  332.     #print('Field goal start')
  333.     #print('ballposition', ballposition)
  334.     ballposition = int(ballposition)
  335.     #print(ballposition)
  336.     totalstats['totalfieldgoalplays'] += 1
  337.     if 4000 <= ballposition <= 4999:
  338.         if possession == hometeam:
  339.             fgmod = ((float(htKicking_Punting['50 FGM']) / float(htKicking_Punting['50 FGA'])) * 100)
  340.             #print('gametime', gametime)
  341.             #print('Field Goal attempt 50+', fgmod)
  342.         if possession == awayteam:
  343.             fgmod = ((float(htKicking_Punting['50 FGM']) / float(htKicking_Punting['50 FGA'])) * 100)
  344.             #print('Field Goal attempt 50+', fgmod)
  345.             #print('gametime', gametime)
  346.     if 5000 <= ballposition <= 5999:
  347.         if possession == hometeam:
  348.             fgmod = ((float(htKicking_Punting['40-49 FGM']) / float(htKicking_Punting['40-49 FGA'])) * 100)
  349.             #print('Field Goal attempt 40-49', fgmod)
  350.             #print('gametime', gametime)
  351.         if possession == awayteam:
  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 6000 <= ballposition <= 6999:
  356.         if possession == hometeam:
  357.             fgmod =((float(htKicking_Punting['30-39 FGM']) / float(htKicking_Punting['30-39 FGA'])) * 100)
  358.             #print('Field Goal attempt 30-39', fgmod)
  359.             #print('gametime', gametime)
  360.         if possession == awayteam:
  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 7000 <= ballposition <= 7999:
  365.         if possession == hometeam:
  366.             fgmod = (float(htKicking_Punting['20-29 FGM']) / float(htKicking_Punting['20-29 FGA'])) * 100
  367.             #print('Field Goal attempt 20-29', fgmod)
  368.             #print('gametime', gametime)
  369.         if possession == awayteam:
  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 ballposition >= 8000:
  374.         fgmod = 99
  375.         #print('Field Goal attempt 0-19', fgmod)
  376.         #print('gametime', gametime)
  377.     fgchance = random.randint(0, 100)
  378.     if fgchance <= fgmod:
  379.         scores[possession] += 3
  380.         #print('fieldgoal made')
  381.         turnover()
  382.         kickoff()
  383.     else:
  384.         turnover()
  385.  
  386. def extrapointexecute():
  387.     global scores
  388.     if possession == hometeam:
  389.         xpmod = float(htKicking_Punting['Scoring XP%'])
  390.     if possession == awayteam:
  391.         xpmod = float(atKicking_Punting['Scoring XP%'])
  392.     xpchance = random.randint(0, 100)
  393.     #print('xp', xpmod, xpchance)
  394.     if xpchance <= xpmod:
  395.         scores[possession] += 1
  396.  
  397. def interceptioncheck():
  398.     global possession
  399.     global hometeam
  400.     global awayteam
  401.     global ballposition
  402.     interceptionchance = random.randint(0, 100)
  403.     if possession == hometeam:
  404.         interceptionodds = (((float(htoffense['Int']) / float(htoffense['Passing Att'])) + (float(atdefense['Passing Int']) / float(atdefense['Passing Att'])) / 2) * 100)
  405.         #print('interceptionodds', interceptionodds, 'interceptionchance', interceptionchance)
  406.         nonpossession = awayteam
  407.     if possession == awayteam:
  408.         interceptionodds = (((float(atoffense['Int']) / float(atoffense['Passing Att'])) + (float(htdefense['Passing Int']) / float(htdefense['Passing Att'])) / 2) * 100)
  409.         #print('interceptionodds', interceptionodds, 'interceptionchance', interceptionchance)
  410.         nonpossession = hometeam
  411.     if interceptionodds >= interceptionchance:
  412.         #print(' ')
  413.         #print(' ')
  414.         #print(' ')
  415.         #print(' ')
  416.         #print('Interception! ', nonpossession, ' intercepts the ball from', possession)
  417.         pick6chance = random.randint(0, 100)
  418.         if pick6chance >= 99:
  419.             #print('Interception! ', nonpossession, ' intercepts the ball from', possession)
  420.             #print('Pick 6!')
  421.             #print(scores)
  422.             scores[nonpossession] += 6
  423.             #print(scores)
  424.             #print(possession, 'posession pre turnover')
  425.             turnover()
  426.             #print(possession, 'posession post turnover')
  427.             extrapointexecute()
  428.             #print(possession, 'posession post extra point')
  429.             #print(scores)
  430.             turnover()
  431.             #print(possession, 'posession post second turnover')
  432.             kickoff()
  433.             #print(possession, 'posession post kickoff')
  434.         else:
  435.             turnover()
  436.  
  437. def fumblecheck():
  438.     global possession
  439.     global hometeam
  440.     global awayteam
  441.     global ballposition
  442.     fumblechance = random.randint(0, 100)
  443.     if possession == hometeam:
  444.         fumbleodds = (((float(htoffense['FL']) / float(htoffense['Rushing Att'])) + (float(atdefense['FL']) / float(atdefense['Rushing  Att'])) / 2) * 100)
  445.         #print('fumbleodds', fumbleodds, 'fumblechance', fumblechance)
  446.         nonpossession = awayteam
  447.     if possession == awayteam:
  448.         fumbleodds = (((float(atoffense['FL']) / float(atoffense['Rushing Att'])) + (float(htdefense['FL']) / float(htdefense['Rushing  Att'])) / 2) * 100)
  449.         #print('fumbleodds', fumbleodds, 'fumblechance', fumblechance)
  450.         nonpossession = hometeam
  451.     if fumbleodds >= fumblechance:
  452.         #print(' ')
  453.         #print(' ')
  454.         #print(' ')
  455.         #print(' ')
  456.         #print('Fumble! ', nonpossession, ' recovers the ball from', possession)
  457.         fumble6chance = random.randint(0, 100)
  458.         if fumble6chance >= 99:
  459.             #print('Fumble 6!')
  460.             #print('Fumble! ', nonpossession, ' recovers the ball from', possession)
  461.             #print(scores)
  462.             scores[nonpossession] += 6
  463.             #print(scores)
  464.             turnover()
  465.             extrapointexecute()
  466.             #print(scores)
  467.             kickoff()
  468.         else:
  469.             turnover()
  470.  
  471. def penaltycheck():
  472.     global possession
  473.     global seriesyards
  474.     global ballposition
  475.     global down
  476.     global gametime
  477.     global totalpenaltyyards
  478.     global scores
  479.     offensepenaltychance = random.randint(0, 100)
  480.     defensepenaltychance = random.randint(0, 100)
  481.  
  482.     if possession == hometeam:
  483.         offensepenaltyodds = ((float(htoffense['Pen Ct']) / float(htoffense['Tot Ply'])) * 100)
  484.         offensepenaltyyards = ((float(htoffense['Pen Yds']) / float(htoffense['Pen Ct'])) * 100)
  485.         defensepenaltyodds = ((float(atdefense['Pen Ct']) / float(atdefense['Ply'])) * 100)
  486.         defensepenaltyyards = ((float(atdefense['Pen Yds']) / float(atdefense['Pen Ct'])) * 100)
  487.         if offensepenaltychance <= offensepenaltyodds:
  488.             gametime -= random.uniform(.2, .6)
  489.             #print(possession, offensepenaltyodds, ' | ', 'offensepenaltyyards', offensepenaltyyards)
  490.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  491.             ballposition -= offensepenaltyyards
  492.             seriesyards -= offensepenaltyyards
  493.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  494.             totalpenaltyyards += offensepenaltyyards
  495. #### Need to implement safety
  496.         if defensepenaltychance <= defensepenaltyodds:
  497.             gametime -= random.uniform(.2, .6)
  498.             #print(possession, defensepenaltyyards,'defpenaltyyards', ' | ', 'defensepenaltyodds', defensepenaltyodds)
  499.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  500.             ballposition += offensepenaltyyards
  501.             seriesyards += offensepenaltyyards
  502.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  503.             totalpenaltyyards += offensepenaltyyards
  504.  
  505.     if possession == awayteam:
  506.         offensepenaltyodds = ((float(atoffense['Pen Ct']) / float(atoffense['Tot Ply'])) * 100)
  507.         offensepenaltyyards = ((float(atoffense['Pen Yds']) / float(atoffense['Pen Ct'])) * 100)
  508.         defensepenaltyodds = ((float(htdefense['Pen Ct']) / float(htdefense['Ply'])) * 100)
  509.         defensepenaltyyards = ((float(htdefense['Pen Yds']) / float(htdefense['Pen Ct'])) * 100)
  510.         if offensepenaltychance <= offensepenaltyodds:
  511.             gametime -= random.uniform(.2, .6)
  512.             #print(possession, offensepenaltyodds, ' | ', 'offensepenaltyyards', offensepenaltyyards)
  513.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  514.             ballposition -= offensepenaltyyards
  515.             seriesyards -= offensepenaltyyards
  516.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  517.             totalpenaltyyards += offensepenaltyyards
  518.         if defensepenaltychance <= defensepenaltyodds:
  519.             gametime -= random.uniform(.2, .6)
  520.             #print(possession, defensepenaltyyards,'defpenaltyyards', ' | ', 'defensepenaltyodds', defensepenaltyodds)
  521.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  522.             ballposition += offensepenaltyyards
  523.             seriesyards += offensepenaltyyards
  524.             #print('ballposition', ballposition, 'seriesyards', seriesyards)
  525.             totalpenaltyyards += offensepenaltyyards
  526.  
  527.     if seriesyards >= 1000:
  528.         down = 1
  529.         #print('first down', down)
  530.         seriesyards = 0
  531.         #print('ballposition', ballposition)
  532.  
  533.  
  534.  
  535. def turnover():
  536.     global down
  537.     global ballposition
  538.     global possession
  539.     global seriesyards
  540.     down = 1
  541.     ballposition = abs(ballposition - 1000)
  542.     if possession == hometeam:
  543.         possession = awayteam
  544.     else:
  545.         possession = hometeam
  546.     seriesyards = 0
  547.     #print('possession', possession)
  548.     #print('ballposition', ballposition)
  549.     #print('gametime', gametime)
  550.  
  551. def executeplay():
  552.     global playchoice
  553.     global gametime
  554.     gametime -= random.uniform(.2, .6)
  555.     penaltycheck()
  556.     if playchoice == 'passplay':
  557.         passplayexecute()
  558.     if playchoice == 'runplay':
  559.         runplayexecute()
  560.     if playchoice == 'fieldgoalplay':
  561.         fieldgoalplayexecute()
  562.     if playchoice == 'puntplay':
  563.         puntplayexecute()
  564.     #print(playchoice, possession)
  565.  
  566. def game():
  567.     teamstats()
  568.     cointoss()
  569.     kickoff()
  570.     while gametime >= 30:
  571.         chooseplay()
  572.         executeplay()
  573.     halftime()
  574.     while gametime >= 0:
  575.         chooseplay()
  576.         executeplay()
  577.     #print('scores: ', scores)
  578.     #print('gametime Over')
  579.     global wins
  580.     winner = max(scores.keys(), key=(lambda k: scores[k]))
  581.     #print('winner :', winner)
  582.     global totalscores
  583.     hometeamscores = scores[hometeam]
  584.     awayteamscores = scores[awayteam]
  585.     totalscores[hometeam] += hometeamscores
  586.     totalscores[awayteam] += awayteamscores
  587.     global end
  588.  
  589. def printstats():
  590.     global totalpassplays
  591.     global totalpassyards
  592.     global totalcompletions
  593.     global end
  594.     global start
  595.     global gamesplayed
  596.     global finalscores
  597.     global matchcount
  598.     #print('Total Scores: ', totalscores)
  599.     #print('Total Yards per attempt: ', (totalstats['totalpassyards'] / totalstats['totalpassplays']) / 100)
  600.     #print('Total Average yards per completion', (totalstats['totalpassyards'] / totalstats['totalcompletions']) / 100)
  601.     #print('Total per Carry: ', (totalstats['totalrushyards'] / totalstats['totalrunplays']) / 100)
  602.     #print('Total yards per punt: ', (totalstats['totalpuntyards'] / totalstats['totalpuntplays']) / 100)
  603.     htstats['comp percent'] = 100 * (htstats['totalcompletions'] / htstats['totalpassplays'])
  604.     htstats['YP COMP'] = (htstats['totalpassyards'] / htstats['totalcompletions']) / 100
  605.     htstats['YP Carry'] = (htstats['totalrushyards'] / htstats['totalrunplays']) / 100
  606.     atstats['comp percent'] = 100 * (atstats['totalcompletions'] / atstats['totalpassplays'])
  607.     atstats['YP COMP'] = (atstats['totalpassyards'] / atstats['totalcompletions']) / 100
  608.     atstats['YP Carry'] = (atstats['totalrushyards'] / atstats['totalrunplays']) / 100
  609.     #print(hometeam, htstats)
  610.     #print(awayteam, atstats)
  611.     #print(hometeam,'completion %: ', htstats['comp percent'],' Yards Per completion: ', htstats['YP COMP'],'Yards Per Carry: ', htstats['YP Carry'] )
  612.     #print(awayteam,'completion %: ', atstats['comp percent'],' Yards Per completion: ', atstats['YP COMP'],'Yards Per Carry: ', atstats['YP Carry'] )
  613.     #print('Average scores :', hometeam, (totalscores[hometeam] / gamesplayed), awayteam, (totalscores[awayteam] / gamesplayed))
  614.     end = timer()
  615.     #print('time: ', (end - start) )
  616.     #print('')
  617.     finalscores.append(hometeam + ' : ' + str((totalscores[hometeam] / gamesplayed)) + ' | ' + awayteam + ' : ' + str((totalscores[awayteam] / gamesplayed)))
  618.  
  619.  
  620. def match():
  621.     global games
  622.     global offset
  623.     global gamesplayed
  624.     global matchcount
  625.     global totalpenaltyyards
  626.     statsreset()
  627.     for i in range(gamesplayed):
  628.         game()
  629.         games += 1
  630.         if games >= offset:
  631.             #print('Percent complete: ', int(( 100 * (offset / gamesplayed))), ' | Match Number: ', matchcount)
  632.             offset += 10000
  633.     matchcount += 1
  634.     printstats()
  635.     #print(totalpenaltyyards)
  636.  
  637. gamesplayed = 1
  638. hometeam = 'Philadelphia Eagles'
  639. awayteam = 'New York Giants'
  640. match()
  641.  
  642. hometeam = 'Seattle Seahawks'
  643. awayteam = 'Oakland Raiders'
  644. match()
  645.  
  646. hometeam = 'Los Angeles Chargers'
  647. awayteam = 'Cleveland Browns'
  648. match()
  649.  
  650. hometeam = 'Tampa Bay Buccaneers'
  651. awayteam = 'Atlanta Falcons'
  652. match()
  653.  
  654. hometeam = 'Buffalo Bills'
  655. awayteam = 'Houston Texans'
  656. match()
  657.  
  658. hometeam = 'Carolina Panthers'
  659. awayteam = 'Washington Redskins'
  660. match()
  661.  
  662. hometeam = 'Baltimore Ravens'
  663. awayteam = 'Tennessee Titans'
  664. match()
  665.  
  666. hometeam = 'Kansas City Chiefs'
  667. awayteam = 'New England Patriots'
  668. match()
  669.  
  670. hometeam = 'Indianapolis Colts'
  671. awayteam = 'New York Jets'
  672. match()
  673.  
  674. hometeam = 'Chicago Bears'
  675. awayteam = 'Miami Dolphins'
  676. match()
  677.  
  678. hometeam = 'Arizona Cardinals'
  679. awayteam = 'Minnesota Vikings'
  680. match()
  681.  
  682. hometeam = 'Pittsburgh Steelers'
  683. awayteam = 'Cincinnati Bengals'
  684. match()
  685.  
  686. hometeam = 'Los Angeles Rams'
  687. awayteam = 'Denver Broncos'
  688. match()
  689.  
  690. hometeam = 'Jacksonville Jaguars'
  691. awayteam = 'Dallas Cowboys'
  692. match()
  693.  
  694. hometeam = 'San Francisco 49ers'
  695. awayteam = 'Green Bay Packers'
  696. match()
  697.  
  698. #hometeam = 'Detroit Lions'
  699. #awayteam = 'Green Bay Packers'
  700. #match()
  701. print(finalscores)
  702. print('time: ', (end - start) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement