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

@@ -1,5 +1,5 @@
import java.lang.Math;
import java.util.*;
import java.util.*;
import java.util.Scanner;
/* The basketball class is a computer game that allows you to play as
@@ -15,7 +15,7 @@ public class Basketball {
int shot = -1;
List<Integer> shot_choices = Arrays.asList(0, 1, 2, 3, 4);
double opponent_chance = 0;
String opponent = null;
String opponent = null;
public Basketball() {
@@ -41,7 +41,7 @@ public class Basketball {
else {
scanner.next();
}
// makes sure that input is legal
while (!defense_choices.contains(defense)) {
System.out.print("Your new defensive allignment is? ");
@@ -57,7 +57,7 @@ public class Basketball {
// takes input for opponent's name
System.out.print("\nChoose your opponent? ");
opponent = scanner.next();
opponent = scanner.next();
start_of_period();
}
@@ -67,13 +67,13 @@ public class Basketball {
score[team] += points;
print_score();
}
private void ball_passed_back() {
System.out.print("Ball passed back to you. ");
dartmouth_ball();
}
// change defense, called when the user enters 0 for their shot
private void change_defense() {
defense = -1;
@@ -82,13 +82,13 @@ public class Basketball {
while (!defense_choices.contains(defense)) {
System.out.println("Your new defensive allignment is? ");
if (scanner.hasNextDouble()) {
defense = (double)(scanner.nextDouble());
defense = (double)(scanner.nextDouble());
}
else {
continue;
continue;
}
}
dartmouth_ball();
}
@@ -102,15 +102,15 @@ public class Basketball {
}
else {
System.out.println("Shooter makes one shot and misses one.");
score[team] += 1;
}
score[team] += 1;
}
}
else {
System.out.println("Shooter makes both shots.");
score[team] += 2;
}
print_score();
print_score();
}
// called when time = 50, starts a new period
@@ -127,13 +127,13 @@ public class Basketball {
// simulates a center jump for posession at the beginning of a period
private void start_of_period() {
System.out.println("Center jump");
System.out.println("Center jump");
if (Math.random() > .6) {
System.out.println("Dartmouth controls the tap.\n");
System.out.println("Dartmouth controls the tap.\n");
dartmouth_ball();
}
else {
System.out.println(opponent + " controls the tap.\n");
System.out.println(opponent + " controls the tap.\n");
opponent_ball();
}
}
@@ -142,10 +142,10 @@ public class Basketball {
private void two_minute_warning() {
System.out.println(" *** Two minutes left in the game ***");
}
// called when the user enters 1 or 2 for their shot
private void dartmouth_jump_shot() {
time ++;
time ++;
if (time == 50) {
halftime();
}
@@ -171,135 +171,135 @@ public class Basketball {
else {
if (Math.random() > .5) {
System.out.println("Shot is blocked. Ball controlled by " +
opponent + ".\n");
opponent_ball();
}
opponent + ".\n");
opponent_ball();
}
else {
System.out.println("Shot is blocked. Ball controlled by Dartmouth.");
dartmouth_ball();
}
System.out.println("Shot is blocked. Ball controlled by Dartmouth.");
dartmouth_ball();
}
}
}
else {
System.out.println("Shot is off target.");
System.out.println("Shot is off target.");
if (defense / 6 * Math.random() > .45) {
System.out.println("Rebound to " + opponent + "\n");
opponent_ball();
}
System.out.println("Rebound to " + opponent + "\n");
opponent_ball();
}
else {
System.out.println("Dartmouth controls the rebound.");
System.out.println("Dartmouth controls the rebound.");
if (Math.random() > .4) {
if (defense == 6 && Math.random() > .6) {
System.out.println("Pass stolen by " + opponent
+ ", easy lay up");
add_points(0, 2);
dartmouth_ball();
}
+ ", easy lay up");
add_points(0, 2);
dartmouth_ball();
}
else {
// ball is passed back to you
ball_passed_back();
}
ball_passed_back();
}
}
else {
System.out.println("");
dartmouth_non_jump_shot();
System.out.println("");
dartmouth_non_jump_shot();
}
}
}
}
}
else {
System.out.println("Shot is good.");
add_points(1, 2);
opponent_ball();
System.out.println("Shot is good.");
add_points(1, 2);
opponent_ball();
}
}
// called when the user enters 0, 3, or 4
// lay up, set shot, or defense change
private void dartmouth_non_jump_shot() {
time ++;
time ++;
if (time == 50) {
halftime();
}
else if (time == 92) {
two_minute_warning();
}
if (shot == 4) {
System.out.println("Set shot.");
}
else if (shot == 3) {
System.out.println("Lay up.");
System.out.println("Lay up.");
}
else if (shot == 0) {
change_defense();
change_defense();
}
// simulates different outcomes after a lay up or set shot
if (7/defense*Math.random() > .4) {
if (7/defense*Math.random() > .7) {
if (7/defense*Math.random() > .875) {
if (7/defense*Math.random() > .925) {
System.out.println("Charging foul. Dartmouth loses the ball.\n");
opponent_ball();
System.out.println("Charging foul. Dartmouth loses the ball.\n");
opponent_ball();
}
else {
System.out.println("Shot blocked. " + opponent + "'s ball.\n");
opponent_ball();
System.out.println("Shot blocked. " + opponent + "'s ball.\n");
opponent_ball();
}
}
else {
foul_shots(1);
opponent_ball();
foul_shots(1);
opponent_ball();
}
}
else {
System.out.println("Shot is off the rim.");
System.out.println("Shot is off the rim.");
if (Math.random() > 2/3) {
System.out.println("Dartmouth controls the rebound.");
System.out.println("Dartmouth controls the rebound.");
if (Math.random() > .4) {
System.out.println("Ball passed back to you.\n");
dartmouth_ball();
System.out.println("Ball passed back to you.\n");
dartmouth_ball();
}
else {
dartmouth_non_jump_shot();
dartmouth_non_jump_shot();
}
}
else {
System.out.println(opponent + " controls the rebound.\n");
opponent_ball();
System.out.println(opponent + " controls the rebound.\n");
opponent_ball();
}
}
}
else {
System.out.println("Shot is good. Two points.");
add_points(1, 2);
opponent_ball();
System.out.println("Shot is good. Two points.");
add_points(1, 2);
opponent_ball();
}
}
// plays out a Dartmouth posession, starting with your choice of shot
private void dartmouth_ball() {
Scanner scanner = new Scanner(System.in); // creates a scanner
System.out.print("Your shot? ");
shot = -1;
System.out.print("Your shot? ");
shot = -1;
if (scanner.hasNextInt()) {
shot = scanner.nextInt();
shot = scanner.nextInt();
}
else {
System.out.println("");
scanner.next();
scanner.next();
}
while (!shot_choices.contains(shot)) {
System.out.print("Incorrect answer. Retype it. Your shot?");
if (scanner.hasNextInt()) {
shot = scanner.nextInt();
shot = scanner.nextInt();
}
else {
System.out.println("");
scanner.next();
scanner.next();
}
}
@@ -308,154 +308,154 @@ public class Basketball {
dartmouth_jump_shot();
}
else {
dartmouth_non_jump_shot();
dartmouth_non_jump_shot();
}
}
else {
if (score[0] != score[1]) {
System.out.println("\n ***** End Of Game *****");
System.out.println("\n ***** End Of Game *****");
System.out.println("Final Score: Dartmouth: " + score[1] + " "
+ opponent + ": " + score[0]);
+ opponent + ": " + score[0]);
System.exit(0);
}
else {
System.out.println("\n ***** End Of Second Half *****");
System.out.println("Score at end of regulation time:");
System.out.println("\n ***** End Of Second Half *****");
System.out.println("Score at end of regulation time:");
System.out.println(" Dartmouth: " + score[1] + " " +
opponent + ": " + score[0]);
System.out.println("Begin two minute overtime period");
time = 93;
start_of_period();
opponent + ": " + score[0]);
System.out.println("Begin two minute overtime period");
time = 93;
start_of_period();
}
}
}
// simulates the opponents jumpshot
private void opponent_jumpshot() {
System.out.println("Jump Shot.");
System.out.println("Jump Shot.");
if (8/defense*Math.random() > .35) {
if (8/defense*Math.random() > .75) {
if (8/defense*Math.random() > .9) {
System.out.println("Offensive foul. Dartmouth's ball.\n");
dartmouth_ball();
System.out.println("Offensive foul. Dartmouth's ball.\n");
dartmouth_ball();
}
else {
foul_shots(0);
dartmouth_ball();
foul_shots(0);
dartmouth_ball();
}
}
else {
System.out.println("Shot is off the rim.");
System.out.println("Shot is off the rim.");
if (defense/6*Math.random() > .5) {
System.out.println(opponent + " controls the rebound.");
if (defense == 6) {
if (Math.random() > .75) {
System.out.println("Ball stolen. Easy lay up for Dartmouth.");
add_points(1, 2);
opponent_ball();
System.out.println("Ball stolen. Easy lay up for Dartmouth.");
add_points(1, 2);
opponent_ball();
}
else {
if (Math.random() > .5) {
System.out.println("");
opponent_non_jumpshot();
System.out.println("");
opponent_non_jumpshot();
}
else {
System.out.println("Pass back to " + opponent +
" guard.\n");
opponent_ball();
" guard.\n");
opponent_ball();
}
}
}
else {
if (Math.random() > .5) {
opponent_non_jumpshot();
opponent_non_jumpshot();
}
else {
System.out.println("Pass back to " + opponent +
" guard.\n");
opponent_ball();
" guard.\n");
opponent_ball();
}
}
}
else {
System.out.println("Dartmouth controls the rebound.\n");
dartmouth_ball();
System.out.println("Dartmouth controls the rebound.\n");
dartmouth_ball();
}
}
}
}
else {
System.out.println("Shot is good.");
add_points(0, 2);
dartmouth_ball();
System.out.println("Shot is good.");
add_points(0, 2);
dartmouth_ball();
}
}
// simulates opponents lay up or set shot
private void opponent_non_jumpshot() {
if (opponent_chance > 3) {
System.out.println("Set shot.");
System.out.println("Set shot.");
}
else {
System.out.println("Lay up");
System.out.println("Lay up");
}
if (7/defense*Math.random() > .413) {
System.out.println("Shot is missed.");
System.out.println("Shot is missed.");
if (defense/6*Math.random() > .5) {
System.out.println(opponent + " controls the rebound.");
System.out.println(opponent + " controls the rebound.");
if (defense == 6) {
if (Math.random() > .75) {
System.out.println("Ball stolen. Easy lay up for Dartmouth.");
add_points(1, 2);
opponent_ball();
System.out.println("Ball stolen. Easy lay up for Dartmouth.");
add_points(1, 2);
opponent_ball();
}
else {
if (Math.random() > .5) {
System.out.println("");
opponent_non_jumpshot();
System.out.println("");
opponent_non_jumpshot();
}
else {
System.out.println("Pass back to " + opponent +
" guard.\n");
opponent_ball();
" guard.\n");
opponent_ball();
}
}
}
else {
if (Math.random() > .5) {
System.out.println("");
opponent_non_jumpshot();
System.out.println("");
opponent_non_jumpshot();
}
else {
System.out.println("Pass back to " + opponent + " guard\n");
opponent_ball();
System.out.println("Pass back to " + opponent + " guard\n");
opponent_ball();
}
}
}
else {
System.out.println("Dartmouth controls the rebound.\n");
dartmouth_ball();
System.out.println("Dartmouth controls the rebound.\n");
dartmouth_ball();
}
}
else {
System.out.println("Shot is good.");
add_points(0, 2);
dartmouth_ball();
System.out.println("Shot is good.");
add_points(0, 2);
dartmouth_ball();
}
}
// simulates an opponents possesion
// #randomly picks jump shot or lay up / set shot.
private void opponent_ball() {
time ++;
time ++;
if (time == 50) {
halftime();
}
opponent_chance = 10/4*Math.random()+1;
opponent_chance = 10/4*Math.random()+1;
if (opponent_chance > 2) {
opponent_non_jumpshot();
opponent_non_jumpshot();
}
else {
opponent_jumpshot();
opponent_jumpshot();
}
}
@@ -463,7 +463,3 @@ public class Basketball {
Basketball new_game = new Basketball();
}
}

View File

@@ -12,10 +12,10 @@ function input()
{
var input_element;
var input_str;
return new Promise(function (resolve) {
input_element = document.createElement("INPUT");
print("? ");
input_element.setAttribute("type", "text");
input_element.setAttribute("length", "50");

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: