Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from timeit import default_timer as timer
- global scores
- start = timer()
- totalplays = 150
- gametime = 60
- playtime = .4
- hometeam = 'patriots'
- awayteam = 'rams'
- posession = None
- ballposition = 0
- scores = {hometeam:0, awayteam:0}
- totalplays = {}
- down = 0
- seriesyards = 0
- touchdown = 'No'
- awayteamscores = 0
- hometeamscores = 0
- totalscores = {hometeam:0, awayteam:0}
- totalrunplays = 0
- totalpassplays = 0
- totalpuntplays = 0
- totalfieldgoalplays = 0
- totalrushyards = 0
- totalpassyards = 0
- totalpuntyards = 0
- def cointoss():
- global gametime
- global posession
- global halftimeposession
- global scores
- gametime = 60
- scores = {hometeam:0, awayteam:0}
- cointossresult = random.randint(1, 2)
- if cointossresult == 1:
- posession = hometeam
- halftimeposession = awayteam
- else:
- posession = awayteam
- halftimeposession = hometeam
- print('cointoss winner', posession)
- def halftime():
- global posession
- global halftimeposession
- global scores
- global ballposition
- if ballposition >= 50:
- fieldgoalodds = ballposition + random.randint(25, 50)
- if fieldgoalodds >= 95:
- scores[posession] += 3
- #print('fieldgoal')
- posession = halftimeposession
- #print('halftime')
- kickoff()
- def kickoff():
- global ballposition
- global gametime
- global posession
- global down
- ballposition = 0
- returnteam = posession
- kickofftd = random.randint(1, 100)
- fumblechance = random.randint(1, 1000)
- gametime -= playtime
- if kickofftd <= 1:
- scores[returnteam] += 6
- turnover()
- kickoff()
- else:
- ballposition += 25
- down = 1
- kickoffbigplay = random.randint(1, 100)
- if kickoffbigplay <= 4:
- ballposition += random.randint(1, 25)
- #print('Kickoff big play!', kickoffbigplay)
- if fumblechance <= 5:
- turnover()
- #print('Fumble')
- #print('posession', posession)
- #print('ballposition', ballposition)
- #print('gametime', gametime)
- print('posession', posession, ' ', 'ballposition', ballposition)
- print('gametime', gametime)
- def chooseplay():
- delaystart = timer()
- delaystop = timer()
- while (delaystop - delaystart) < 4:
- delaystop = timer()
- global posession
- global down
- global playchoice
- global ballposition
- offense = posession
- if down < 4:
- playchoice = random.randint(1, 100)
- if playchoice >= 55:
- playchoice = 'passplay'
- else: playchoice = 'runplay'
- else:
- if ballposition > 60:
- playchoice = 'fieldgoalplay'
- else:
- playchoice = 'puntplay'
- print ('\n')
- print(posession, playchoice)
- def passplayexecute():
- global posession
- global nonposession
- global ballposition
- global down
- global seriesyards
- global totalpassyards
- global totalpassplays
- totalpassplays += 1
- completionchace = random.randint(1,100)
- if completionchace <= 66:
- print('Pass complete')
- down += 1
- playyards = 11 + random.randint(-11, 13)
- totalpassyards += playyards
- print('playyards', playyards)
- ballposition += playyards
- seriesyards += playyards
- if ballposition >= 100:
- scores[posession] += 7
- print(' passing touchdown')
- print(scores)
- touchdown = 'yes'
- turnover()
- kickoff()
- if seriesyards >= 10:
- down = 1
- print('first down', down, posession)
- seriesyards = 0
- print('ballposition', ballposition)
- else:
- down += 1
- print('incomplete')
- def runplayexecute():
- global posession
- global ballposition
- global down
- global seriesyards
- global touchdown
- global totalrunplays
- global totalrushyards
- totalrunplays += 1
- rungainchance = random.randint(1,100)
- if rungainchance <= 70:
- print('Positive Run', posession)
- down += 1
- playyards = int(4.2 + (random.randint(-30, 100) / 10))
- print('playyards', playyards)
- ballposition += playyards
- seriesyards += playyards
- if ballposition >= 100:
- scores[posession] += 7
- print('rushing touchdown')
- print(scores)
- turnover()
- kickoff()
- if seriesyards >= 10:
- down = 1
- print('first down', down, posession)
- seriesyards = 0
- print('ballposition', ballposition)
- else:
- down += 1
- print('negtive run', posession)
- playyards = int(random.randint(-3, 0))
- print('playyards', playyards)
- ballposition += playyards
- seriesyards += playyards
- totalrushyards += playyards
- def puntplayexecute():
- global ballposition
- global posession
- global ballposition
- global down
- global totalpuntplays
- global totalpuntyards
- totalpuntplays += 1
- puntyards = 45 + random.randint(-20, 20)
- totalpuntyards += puntyards
- print('puntyards', puntyards)
- ballposition += puntyards
- if ballposition >= 100:
- ballposition = 80
- turnover()
- def fieldgoalplayexecute():
- global scores
- global ballposition
- global totalfieldgoalplays
- totalfieldgoalplays += 1
- fieldgoalodds = ballposition + random.randint(25, 50)
- if fieldgoalodds >= 92:
- scores[posession] += 3
- print('fieldgoal', scores)
- turnover()
- kickoff()
- else:
- turnover()
- def turnover():
- global down
- global ballposition
- global posession
- global seriesyards
- down = 1
- ballposition = abs(ballposition - 100)
- if posession == hometeam:
- posession = awayteam
- else:
- posession = hometeam
- seriesyards = 0
- print('posession', posession)
- print('ballposition', ballposition)
- print('gametime', gametime)
- def executeplay():
- global playchoice
- global gametime
- gametime -= playtime
- if playchoice == 'passplay':
- passplayexecute()
- if playchoice == 'runplay':
- runplayexecute()
- if playchoice == 'fieldgoalplay':
- fieldgoalplayexecute()
- if playchoice == 'puntplay':
- puntplayexecute()
- def game():
- cointoss()
- kickoff()
- while gametime >= 30:
- chooseplay()
- executeplay()
- halftime()
- while gametime >= 0:
- chooseplay()
- executeplay()
- print('scores: ', scores)
- print('gametime Over')
- global wins
- winner = max(scores.keys(), key=(lambda k: scores[k]))
- print('winner :', winner)
- global totalscores
- hometeamscores = scores[hometeam]
- awayteamscores = scores[awayteam]
- totalscores[hometeam] += hometeamscores
- totalscores[awayteam] += awayteamscores
- print(totalscores)
- print('Yards per attempt: ', (totalpassyards / totalpassplays))
- print('Yards per Carry: ', (totalrushyards / totalrunplays))
- print('yards per punt: ', (totalpuntyards / totalpuntplays))
- print('Average scores :', (totalscores[hometeam] / 500), (totalscores[awayteam] / 500))
- for i in range(500):
- game()
- end = timer()
- print('time: ', (end - start) * 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement