mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-02-04 11:07:59 -08:00
Merge pull request #939 from bwignall/fix_flake8_errors
Fix flake8 errors for Python code
This commit is contained in:
@@ -131,7 +131,7 @@ def main() -> None:
|
||||
# Main loop of game
|
||||
print_intro()
|
||||
while (
|
||||
keep_playing := parse_input(
|
||||
parse_input(
|
||||
"Are you thinking of an animal? ", True, root
|
||||
)
|
||||
== "y"
|
||||
|
||||
@@ -139,7 +139,7 @@ class Basketball:
|
||||
else:
|
||||
print("Shot is off target.")
|
||||
if self.defense / 6 * random.random() > 0.45:
|
||||
print(f"Rebound to {self.opponent}" + "\n")
|
||||
print(f"Rebound to {self.opponent}\n")
|
||||
self.opponent_ball()
|
||||
else:
|
||||
print("Dartmouth controls the rebound.")
|
||||
@@ -185,7 +185,7 @@ class Basketball:
|
||||
if 7 / self.defense * random.random() > 0.925:
|
||||
print("Charging foul. Dartmouth loses the ball.\n")
|
||||
else:
|
||||
print(f"Shot blocked. {self.opponent}" + "'s ball.\n")
|
||||
print(f"Shot blocked. {self.opponent}'s ball.\n")
|
||||
else:
|
||||
self.foul_shots(1)
|
||||
self.opponent_ball()
|
||||
@@ -270,7 +270,7 @@ class Basketball:
|
||||
or self.defense != 6
|
||||
and random.random() <= 0.5
|
||||
):
|
||||
print(f"Pass back to {self.opponent}" + " guard.\n")
|
||||
print(f"Pass back to {self.opponent} guard.\n")
|
||||
self.opponent_ball()
|
||||
elif self.defense == 6 and random.random() > 0.75:
|
||||
print("Ball stolen. Easy lay up for Dartmouth.")
|
||||
@@ -310,14 +310,14 @@ class Basketball:
|
||||
and random.random() <= 0.75
|
||||
and random.random() <= 0.5
|
||||
):
|
||||
print(f"Pass back to {self.opponent}" + " guard.\n")
|
||||
print(f"Pass back to {self.opponent} guard.\n")
|
||||
self.opponent_ball()
|
||||
elif self.defense == 6 and random.random() > 0.75:
|
||||
print("Ball stolen. Easy lay up for Dartmouth.")
|
||||
self.add_points(1, 2)
|
||||
self.opponent_ball()
|
||||
else:
|
||||
print(f"Pass back to {self.opponent}" + " guard\n")
|
||||
print(f"Pass back to {self.opponent} guard\n")
|
||||
self.opponent_ball()
|
||||
else:
|
||||
print("Dartmouth controls the rebound.\n")
|
||||
|
||||
@@ -29,7 +29,7 @@ def determine_player_kills(
|
||||
print(f"THE {player_type}{plural_form} DID A {job_qualities[job_quality]} JOB.")
|
||||
if job_quality >= 4:
|
||||
if job_quality == 5:
|
||||
if player_was_killed := random.choice([True, False]):
|
||||
if random.choice([True, False]):
|
||||
print(f"ONE OF THE {player_type}{plural_form} WAS KILLED.")
|
||||
else:
|
||||
if player_type != "TOREAD":
|
||||
|
||||
@@ -127,7 +127,7 @@ def print_header() -> None:
|
||||
|
||||
|
||||
def instructions() -> None:
|
||||
if wants_it := ask_binary(
|
||||
if ask_binary(
|
||||
"WOULD YOU LIKE THE INSTRUCTIONS? ", "ANSWER YES OR NO!!"
|
||||
):
|
||||
print()
|
||||
@@ -229,7 +229,7 @@ def team2_action(
|
||||
z1 = 3
|
||||
elif pass_value == 2:
|
||||
print("IT'S A ' 3 ON 2 '!\n")
|
||||
print(f"ONLY {team_a.players[3]} AND {team_a.players[4]}" + " ARE BACK.\n")
|
||||
print(f"ONLY {team_a.players[3]} AND {team_a.players[4]} ARE BACK.\n")
|
||||
print(
|
||||
team_b.players[player_index[j - 2]]
|
||||
+ " GIVES OFF TO "
|
||||
@@ -374,7 +374,7 @@ def handle_hit(
|
||||
else:
|
||||
print(f"{team_b.name}: {team_b.score}\t{team_a.name}: {team_a.score}\n")
|
||||
team = team_a if controlling_team == 1 else team_b
|
||||
print(f"GOAL SCORED BY: {team.players[goal_player]}" + "\n")
|
||||
print(f"GOAL SCORED BY: {team.players[goal_player]}\n")
|
||||
if goal_assistant1 != 0:
|
||||
if goal_assistant2 != 0:
|
||||
print(
|
||||
@@ -402,16 +402,16 @@ def handle_miss(
|
||||
saving_player = randint(1, 7)
|
||||
if controlling_team == 1:
|
||||
if saving_player == 1:
|
||||
print(f"KICK SAVE AND A BEAUTY BY {team_b.players[5]}" + "\n")
|
||||
print(f"CLEARED OUT BY {team_b.players[3]}" + "\n")
|
||||
print(f"KICK SAVE AND A BEAUTY BY {team_b.players[5]}\n")
|
||||
print(f"CLEARED OUT BY {team_b.players[3]}\n")
|
||||
remaining_time -= 1
|
||||
return ("continue", remaining_time)
|
||||
if saving_player == 2:
|
||||
print(f"WHAT A SPECTACULAR GLOVE SAVE BY {team_b.players[5]}" + "\n")
|
||||
print(f"AND {team_b.players[5]}" + " GOLFS IT INTO THE CROWD\n")
|
||||
print(f"WHAT A SPECTACULAR GLOVE SAVE BY {team_b.players[5]}\n")
|
||||
print(f"AND {team_b.players[5]} GOLFS IT INTO THE CROWD\n")
|
||||
return ("break", remaining_time)
|
||||
if saving_player == 3:
|
||||
print(f"SKATE SAVE ON A LOW STEAMER BY {team_b.players[5]}" + "\n")
|
||||
print(f"SKATE SAVE ON A LOW STEAMER BY {team_b.players[5]}\n")
|
||||
remaining_time -= 1
|
||||
return ("continue", remaining_time)
|
||||
if saving_player == 4:
|
||||
@@ -447,20 +447,20 @@ def handle_miss(
|
||||
print("ON THE LOOSE PUCK!\n")
|
||||
return ("break", remaining_time)
|
||||
if saving_player == 3:
|
||||
print(f"SKATE SAVE BY {team_a.players[5]}" + "\n")
|
||||
print(f"SKATE SAVE BY {team_a.players[5]}\n")
|
||||
print(team_a.players[5] + " WHACKS THE LOOSE PUCK INTO THE STANDS\n")
|
||||
return ("break", remaining_time)
|
||||
if saving_player == 4:
|
||||
print(f"STICK SAVE BY {team_a.players[5]}" + " AND HE CLEARS IT OUT HIMSELF\n")
|
||||
print(f"STICK SAVE BY {team_a.players[5]} AND HE CLEARS IT OUT HIMSELF\n")
|
||||
remaining_time -= 1
|
||||
return ("continue", remaining_time)
|
||||
if saving_player == 5:
|
||||
print(f"KICKED OUT BY {team_a.players[5]}" + "\n")
|
||||
print(f"KICKED OUT BY {team_a.players[5]}\n")
|
||||
print("AND IT REBOUNDS ALL THE WAY TO CENTER ICE\n")
|
||||
remaining_time -= 1
|
||||
return ("continue", remaining_time)
|
||||
if saving_player == 6:
|
||||
print(f"GLOVE SAVE {team_a.players[5]}" + " AND HE HANGS ON\n")
|
||||
print(f"GLOVE SAVE {team_a.players[5]} AND HE HANGS ON\n")
|
||||
return ("break", remaining_time)
|
||||
return ("continue", remaining_time)
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ def run_simulation() -> None:
|
||||
return
|
||||
|
||||
if capsule.velocity > 0 and new_state.velocity < 0:
|
||||
if landed := handle_flyaway(sim_clock, capsule):
|
||||
if handle_flyaway(sim_clock, capsule):
|
||||
process_final_tick(delta_t, sim_clock, capsule)
|
||||
return
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ def play_game() -> None:
|
||||
|
||||
print(f"YOUR NUMBER WAS {d}, RIGHT?")
|
||||
|
||||
if response := get_yes_or_no():
|
||||
if get_yes_or_no():
|
||||
print("HOW ABOUT THAT!!")
|
||||
else:
|
||||
print("I FEEL YOUR ARITHMETIC IS IN ERROR.")
|
||||
|
||||
@@ -78,14 +78,14 @@ def main() -> None:
|
||||
|
||||
# Start game loop
|
||||
input("\nPress Enter to start the Game:\n")
|
||||
end = False
|
||||
|
||||
while True:
|
||||
game.print_pegs()
|
||||
|
||||
# Players Move
|
||||
command = input("\nYOUR MOVE - Number of PILE, Number of Object? ")
|
||||
game.remove_pegs(command)
|
||||
if end := game.check_for_win():
|
||||
if game.check_for_win():
|
||||
print("\nPlayer Wins the Game, Congratulations!!")
|
||||
input("\nPress any key to exit")
|
||||
break
|
||||
@@ -96,7 +96,7 @@ def main() -> None:
|
||||
f"\nA.I MOVE - A.I Removed {ai_command[1]} pegs from Pile {ai_command[0]}"
|
||||
)
|
||||
game.remove_pegs(f"{str(ai_command[0])},{str(ai_command[1])}")
|
||||
if end := game.check_for_win():
|
||||
if game.check_for_win():
|
||||
print("\nComputer Wins the Game, Better Luck Next Time\n")
|
||||
input("Press any key to exit")
|
||||
break
|
||||
|
||||
@@ -155,7 +155,7 @@ def main() -> None:
|
||||
|
||||
player_name = print_instructions()
|
||||
|
||||
if more_directions := yes_no_prompt("DO YOU NEED MORE DIRECTIONS?"):
|
||||
if yes_no_prompt("DO YOU NEED MORE DIRECTIONS?"):
|
||||
print_more_directions(player_name)
|
||||
|
||||
understand = yes_no_prompt("UNDERSTAND?")
|
||||
|
||||
@@ -117,9 +117,9 @@ COMPUTER_SAFE_SPOTS: Final[FrozenSet[Tuple[int, int]]] = frozenset(
|
||||
)
|
||||
|
||||
# These are the places that the computer will always try to move into.
|
||||
COMPUTER_PREF_MOVES: Final[
|
||||
FrozenSet[Tuple[int, int]]
|
||||
] = COMPUTER_SAFE_SPOTS | frozenset([WIN_LOC])
|
||||
COMPUTER_PREF_MOVES: Final[FrozenSet[Tuple[int, int]]] = (
|
||||
COMPUTER_SAFE_SPOTS | frozenset([WIN_LOC])
|
||||
)
|
||||
|
||||
# These are the locations (not including the win location) from which either player can
|
||||
# force a win (but the computer will always choose one of the COMPUTER_PREF_MOVES).
|
||||
@@ -171,10 +171,10 @@ def get_move(current_loc: Optional[Tuple[int, int]]) -> Tuple[int, int]:
|
||||
"WHERE WOULD YOU LIKE TO START? "
|
||||
)
|
||||
elif (
|
||||
(new_row == row and new_col < col) # move left
|
||||
or (new_col == col and new_row > row) # move down
|
||||
or (new_row - row == col - new_col) # move diag left and down
|
||||
) and (not FIX_BOARD_BUG or (new_col >= 0 and new_row < 8)):
|
||||
(new_row == row and new_col < col) # move left
|
||||
or (new_col == col and new_row > row) # move down
|
||||
or (new_row - row == col - new_col) # move diag left and down
|
||||
) and (not FIX_BOARD_BUG or (new_col >= 0 and new_row < 8)):
|
||||
return new_row, new_col
|
||||
else:
|
||||
prompt = "Y O U C H E A T . . . TRY AGAIN? "
|
||||
|
||||
@@ -171,7 +171,7 @@ def display(game: TicTacToe) -> None:
|
||||
if game.board[i][game.dim_sz - 1] == "blur":
|
||||
line1 = line1 + " \n"
|
||||
else:
|
||||
line1 = f"{line1} {game.board[i][game.dim_sz - 1]}" + " \n"
|
||||
line1 = f"{line1} {game.board[i][game.dim_sz - 1]} \n"
|
||||
print(line1, "\n\n")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user