Skip to content

Instantly share code, notes, and snippets.

@Kielan
Created December 12, 2024 06:04
Show Gist options
  • Save Kielan/acd2fed2840bd4104f754370b79e1eba to your computer and use it in GitHub Desktop.
Save Kielan/acd2fed2840bd4104f754370b79e1eba to your computer and use it in GitHub Desktop.
Basketball pseudo code from Anthony on github
## Anthony Dike started: 3/8/18
##
## This is VERSION 3 of a program that
## will simulate basketball games like NBA 2k.
##
## In this version I will add
## 1) More Overtime and Sportcasting (announcers and stuff)
## 2) Notifier that says when team is blown out or a close game
## 3) Win Counter
##
## abbreviations:
## ffv: for future versions
"""
NOTES FOR PRE PUblISHING REFERENCES
- should probs make 1 game score print (ie if OT played, oly print OT)
"""
import random
'''
Steps:
1) add more emotive print statement
- for ots, for close games
- make a random function that causes events based on random ints
(snow, rain, winter, summer, celebrities, etc) and make sportscasters
react to that news while talking. DONE
2)
3) make function that counts how many ots occur and if one doesnt
happen after a certain number of times (maybe make that counter # random 1-10)
then an ot game is played
4)
5)
'''
# EVENT SPEECH TRIGGER FUNCTIONS
#def RandomizeEventTriggers():
# use dictionary or list to store event functions
# randomize selection from the container
def WeatherTrigger():
# weather list
weather = ['rain', 'snow', 'sunny']
#randommize index int
weatherToday = weather[random.randint(0,(len(weather) - 1))]
#choose random weather
return weatherToday
def RainTalk():
# commentary list on rain
rainTalk = [
"I hope you all have your umbrellas tonight, sports fans, 'cuz it'll be raining all night!",
"It's raining cats and dogs outside tonight, sports fans!",
"It's been so hot lately, glad we got some rain to cool things down!"
]
# randomize index int
rainTalkChoice = rainTalk[random.randint(0,(len(rainTalk) - 1))]
# choose random commentary choice
return rainTalkChoice
def SnowTalk():
# commentary list on rain
snowTalk = [
"Stay warm sports fans, it's freezing outside today!",
"It is absolutely frigid outside today in the city, hope y'all are warm!",
"Lets all enjoy this game, while the temperatures drop outside!"
]
# randomize index int
snowTalkChoice = snowTalk[random.randint(0,(len(snowTalk) - 1))]
# choose random commentary choice
return snowTalkChoice
def SunnyTalk():
# commentary list on rain
sunnyTalk = [
"It's a beautiful sunny day out today, sports fans!",
"Wouldn't it be great if this game was played outside in the nice weather, sports fans? If only!",
"Such a lovely sunny day for sports!"
]
# randomize index int
sunnyTalkChoice = sunnyTalk[random.randint(0,(len(sunnyTalk) - 1))]
# choose random commentary choice
return sunnyTalkChoice
def OvertimeTeam1():
overtimeAdder = random.randint(0,30)
global Team1
Team1 += overtimeAdder
global team1OT
team1OT = Team1
return team1OT
def OvertimeTeam2():
overtimeAdder = random.randint(0,30)
global Team2
Team2 += overtimeAdder
global team2OT
team2OT = Team2
return team2OT
def SportscastingIntro():
# intro
print("\nWelcome back sports fans! Time for another day of basketball!\n")
#ffv: create team name variables
# weather commentary
weatherToday = WeatherTrigger()
if weatherToday == 'rain':
print(RainTalk())
print()
elif weatherToday == 'snow':
print(SnowTalk())
print()
elif weatherToday == 'sunny':
print(SunnyTalk())
print()
# where the team points calc takes place
def Game():
# create max and min scores
maxScore = 122
minScore = 98
# initialize team variables
global Team1
Team1 = random.randint(minScore, maxScore)
global Team2
Team2 = random.randint(minScore, maxScore)
# if tie trigger overtime
if Team1 == Team2:
otScore1 = OvertimeTeam1()
otScore2 = OvertimeTeam2()
print("There was an overtime!")
# prints overtime
print("OVERTIME: Team 1 - " + str(otScore1) +
" Team 2 - " + str(otScore2))
print()
if otScore1 == otScore2:
Team1 = otScore1
Team2 = otScore2
dotScore1 = OvertimeTeam1()
dotScore2 = OvertimeTeam2()
print("After a well fought regulation and a grueling two overtimes, Team 1 finished with " +
str(dotScore1) + " and Team 2 ended up with " + str(dotScore2))
else:
print("\nREGULATION: Team1 - " + str(Team1) + " Team 2 - " + str(Team2))
# welcome message
print()
print("----------------------------------------------")
print("| HELLO, WELCOME TO THE BASKETBALL SIMULATOR |")
print("----------------------------------------------")
print()
proceed = False
while proceed == False:
print("\t Would you like to start a game?")
print()
answer = input("(YES or NO): ")
print()
if answer.lower() == "yes":
print()
SportscastingIntro()
Game()
print()
elif answer.lower() == "no":
proceed = True
break
else:
print("INVALID INPUT. Try Again.")
print()
# closing message
print()
print("----------------------------------------------")
print("| GOODBYE, THANK YOU FOR PLAYING! |")
print("----------------------------------------------")
print()
class Player:
def __init__(self, first, last, height, weight, agility, strength):
self.first = first
self.last = last
self.height = height # min 185cm:6ft - mid 200cm:6'6ft - max 220cm:7'2ft
self.weight = weight # min 175lbs:80kg - mid 220lbs:100kg - max 320lbs:145kg
self.agility = agility
self.strength = strength
# height, strength, weight, agility = numbers, for easy comparison
def fullname(self):
self.name = "{} {}".format(self.first, self.last)
def off_rating(self, dribble, jumpshot, layup, assist):
# info with rating; but rating will be average of skill points.
# Rating will be 1 - 10 for simplicity right now
self.dribble = dribble
self.jumpshot = jumpshot
self.layup = layup
self.assist = assist
total_off_rating = dribble + jumpshot + layup + assist
avg_off_rating = (total_off_rating / 4.0)
return avg_off_rating
def def_rating(self, steal, block):
self.steal = steal
self.block = block
total_def_rating = steal + block
avg_def_rating = total_def_rating / 2.0
return avg_def_rating
#I am creating six players to try 3-on-3
#player 1
player_1 = Player('Tony', 'Douglass', 205, 100, 6, 6) # average player (sf) ht: 6'6 wt: 220
player_1.off_rating(6, 7, 7, 6) # avg off
player_1.def_rating(5, 5) # avg def
#player 2
player_2 = Player('Greg', 'Johnson', 208, 125, 4, 8) # strong player (pf)
player_2.off_rating(4, 5, 8, 4)
player_2.def_rating(3, 7)
#player 3
player_3 = Player('Jack', 'Heckler', 185, 90, 10, 2) # quick player (pg)
player_3.off_rating(8, 8, 3, 8)
player_3.def_rating(9, 2)
#player 4
player_4 = Player('Fred', 'Ottoman', 215, 300, 2, 10) # physical player (c)
player_4.off_rating(2, 4, 9, 3)
player_4.def_rating(2, 9)
#player 5
player_5 = Player('Anthony', 'Dike', 200, 105, 9, 8) # all star player (sg)
player_5.off_rating(9, 8, 9, 8)
player_5.def_rating(9, 6)
#player 6
player_6 = Player('Kipp', 'Anderson', 205, 110, 4, 4) # ok player (sf)
player_6.off_rating(6, 6, 5, 5)
player_6.def_rating(3, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment