MAINT: Apply pre-commit

Remove byte-order-marker pre-commit check as there would be
many adjustments necessary
This commit is contained in:
Martin Thoma
2022-03-05 09:29:23 +01:00
parent f5e33ae38f
commit e64fb6795c
536 changed files with 6267 additions and 5556 deletions

View File

@@ -6,7 +6,7 @@ import random
# You are able to choose your shot types as well as defensive formations
class Basketball():
class Basketball:
def __init__(self):
self.time = 0
self.score = [0, 0] # first value is opponents score, second is home
@@ -22,12 +22,14 @@ class Basketball():
print("This is Dartmouth College basketball. ")
print("Υou will be Dartmouth captain and playmaker.")
print("Call shots as follows:")
print("1. Long (30ft.) Jump Shot; 2. Short (15 ft.) Jump Shot; "
+ "3. Lay up; 4. Set Shot")
print(
"1. Long (30ft.) Jump Shot; 2. Short (15 ft.) Jump Shot; "
+ "3. Lay up; 4. Set Shot"
)
print("Both teams will use the same defense. Call Defense as follows:")
print("6. Press; 6.5 Man-to-Man; 7. Zone; 7.5 None.")
print("To change defense, just type 0 as your next shot.")
print("Your starting defense will be? ", end='')
print("Your starting defense will be? ", end="")
# takes input for a defense
try:
@@ -38,7 +40,7 @@ class Basketball():
# if the input wasn't a valid defense, takes input again
while self.defense not in self.defense_choices:
print("Your new defensive allignment is? ", end='')
print("Your new defensive allignment is? ", end="")
try:
self.defense = float(input())
@@ -46,7 +48,7 @@ class Basketball():
continue
# takes input for opponent's name
print("\nChoose your opponent? ", end='')
print("\nChoose your opponent? ", end="")
self.opponent = input()
self.start_of_period()
@@ -58,7 +60,7 @@ class Basketball():
self.print_score()
def ball_passed_back(self):
print("Ball passed back to you. ", end='')
print("Ball passed back to you. ", end="")
self.dartmouth_ball()
# change defense, called when the user enters 0 for their shot
@@ -77,8 +79,8 @@ class Basketball():
# simulates two foul shots for a player and adds the points
def foul_shots(self, team):
print("Shooter fouled. Two shots.")
if random.random() > .49:
if random.random() > .75:
if random.random() > 0.49:
if random.random() > 0.75:
print("Both shots missed.")
else:
print("Shooter makes one shot and misses one.")
@@ -97,13 +99,12 @@ class Basketball():
# prints the current score
def print_score(self):
print("Score: " + str(self.score[1])
+ " to " + str(self.score[0]) + "\n")
print("Score: " + str(self.score[1]) + " to " + str(self.score[0]) + "\n")
# simulates a center jump for posession at the beginning of a period
def start_of_period(self):
print("Center jump")
if random.random() > .6:
if random.random() > 0.6:
print("Dartmouth controls the tap.\n")
self.dartmouth_ball()
else:
@@ -123,10 +124,10 @@ class Basketball():
self.two_minute_warning()
print("Jump Shot.")
# simulates chances of different possible outcomes
if random.random() > .341 * self.defense / 8:
if random.random() > .682 * self.defense / 8:
if random.random() > .782 * self.defense / 8:
if random.random() > .843 * self.defense / 8:
if random.random() > 0.341 * self.defense / 8:
if random.random() > 0.682 * self.defense / 8:
if random.random() > 0.782 * self.defense / 8:
if random.random() > 0.843 * self.defense / 8:
print("Charging foul. Dartmouth loses ball.\n")
self.opponent_ball()
else:
@@ -134,24 +135,26 @@ class Basketball():
self.foul_shots(1)
self.opponent_ball()
else:
if random.random() > .5:
print("Shot is blocked. Ball controlled by " +
self.opponent + ".\n")
if random.random() > 0.5:
print(
"Shot is blocked. Ball controlled by "
+ self.opponent
+ ".\n"
)
self.opponent_ball()
else:
print("Shot is blocked. Ball controlled by Dartmouth.")
self.dartmouth_ball()
else:
print("Shot is off target.")
if self.defense / 6 * random.random() > .45:
if self.defense / 6 * random.random() > 0.45:
print("Rebound to " + self.opponent + "\n")
self.opponent_ball()
else:
print("Dartmouth controls the rebound.")
if random.random() > .4:
if self.defense == 6 and random.random() > .6:
print("Pass stolen by " + self.opponent
+ ", easy lay up")
if random.random() > 0.4:
if self.defense == 6 and random.random() > 0.6:
print("Pass stolen by " + self.opponent + ", easy lay up")
self.add_points(0, 2)
self.dartmouth_ball()
else:
@@ -182,10 +185,10 @@ class Basketball():
self.change_defense()
# simulates different outcomes after a lay up or set shot
if 7/self.defense*random.random() > .4:
if 7/self.defense*random.random() > .7:
if 7/self.defense*random.random() > .875:
if 7/self.defense*random.random() > .925:
if 7 / self.defense * random.random() > 0.4:
if 7 / self.defense * random.random() > 0.7:
if 7 / self.defense * random.random() > 0.875:
if 7 / self.defense * random.random() > 0.925:
print("Charging foul. Dartmouth loses the ball.\n")
self.opponent_ball()
else:
@@ -196,9 +199,9 @@ class Basketball():
self.opponent_ball()
else:
print("Shot is off the rim.")
if random.random() > 2/3:
if random.random() > 2 / 3:
print("Dartmouth controls the rebound.")
if random.random() > .4:
if random.random() > 0.4:
print("Ball passed back to you.\n")
self.dartmouth_ball()
else:
@@ -213,7 +216,7 @@ class Basketball():
# plays out a Dartmouth posession, starting with your choice of shot
def dartmouth_ball(self):
print("Your shot? ", end='')
print("Your shot? ", end="")
self.shot = None
try:
self.shot = int(input())
@@ -221,13 +224,13 @@ class Basketball():
self.shot = None
while self.shot not in self.shot_choices:
print("Incorrect answer. Retype it. Your shot? ", end='')
print("Incorrect answer. Retype it. Your shot? ", end="")
try:
self.shot = int(input())
except:
continue
if self.time < 100 or random.random() < .5:
if self.time < 100 or random.random() < 0.5:
if self.shot == 1 or self.shot == 2:
self.dartmouth_jump_shot()
else:
@@ -235,13 +238,25 @@ class Basketball():
else:
if self.score[0] != self.score[1]:
print("\n ***** End Of Game *****")
print("Final Score: Dartmouth: " + str(self.score[1]) + " "
+ self.opponent + ": " + str(self.score[0]))
print(
"Final Score: Dartmouth: "
+ str(self.score[1])
+ " "
+ self.opponent
+ ": "
+ str(self.score[0])
)
else:
print("\n ***** End Of Second Half *****")
print("Score at end of regulation time:")
print(" Dartmouth: " + str(self.score[1]) + " " +
self.opponent + ": " + str(self.score[0]))
print(
" Dartmouth: "
+ str(self.score[1])
+ " "
+ self.opponent
+ ": "
+ str(self.score[0])
)
print("Begin two minute overtime period")
self.time = 93
self.start_of_period()
@@ -249,9 +264,9 @@ class Basketball():
# simulates the opponents jumpshot
def opponent_jumpshot(self):
print("Jump Shot.")
if 8/self.defense*random.random() > .35:
if 8/self.defense*random.random() > .75:
if 8/self.defense*random.random() > .9:
if 8 / self.defense * random.random() > 0.35:
if 8 / self.defense * random.random() > 0.75:
if 8 / self.defense * random.random() > 0.9:
print("Offensive foul. Dartmouth's ball.\n")
self.dartmouth_ball()
else:
@@ -259,27 +274,25 @@ class Basketball():
self.dartmouth_ball()
else:
print("Shot is off the rim.")
if self.defense/6*random.random() > .5:
if self.defense / 6 * random.random() > 0.5:
print(self.opponent + " controls the rebound.")
if self.defense == 6:
if random.random() > .75:
if random.random() > 0.75:
print("Ball stolen. Easy lay up for Dartmouth.")
self.add_points(1, 2)
self.opponent_ball()
else:
if random.random() > .5:
if random.random() > 0.5:
print("")
self.opponent_non_jumpshot()
else:
print("Pass back to " + self.opponent +
" guard.\n")
print("Pass back to " + self.opponent + " guard.\n")
self.opponent_ball()
else:
if random.random() > .5:
if random.random() > 0.5:
self.opponent_non_jumpshot()
else:
print("Pass back to " + self.opponent +
" guard.\n")
print("Pass back to " + self.opponent + " guard.\n")
self.opponent_ball()
else:
print("Dartmouth controls the rebound.\n")
@@ -295,25 +308,24 @@ class Basketball():
print("Set shot.")
else:
print("Lay up")
if 7/self.defense*random.random() > .413:
if 7 / self.defense * random.random() > 0.413:
print("Shot is missed.")
if self.defense/6*random.random() > .5:
if self.defense / 6 * random.random() > 0.5:
print(self.opponent + " controls the rebound.")
if self.defense == 6:
if random.random() > .75:
if random.random() > 0.75:
print("Ball stolen. Easy lay up for Dartmouth.")
self.add_points(1, 2)
self.opponent_ball()
else:
if random.random() > .5:
if random.random() > 0.5:
print("")
self.opponent_non_jumpshot()
else:
print("Pass back to " + self.opponent +
" guard.\n")
print("Pass back to " + self.opponent + " guard.\n")
self.opponent_ball()
else:
if random.random() > .5:
if random.random() > 0.5:
print("")
self.opponent_non_jumpshot()
else:
@@ -333,7 +345,7 @@ class Basketball():
self.time += 1
if self.time == 50:
self.halftime()
self.z1 = 10/4*random.random()+1
self.z1 = 10 / 4 * random.random() + 1
if self.z1 > 2:
self.opponent_non_jumpshot()
else: