mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
Merge pull request #636 from MartinThoma/python-flake8-e711
Python: Fix linting issues / bugs
This commit is contained in:
2
.github/workflows/check-python.yml
vendored
2
.github/workflows/check-python.yml
vendored
@@ -28,4 +28,4 @@ jobs:
|
|||||||
mypy . --exclude 79_Slalom --exclude 27_Civil_War --exclude 38_Fur_Trader --exclude 81_Splat --exclude 09_Battle --exclude 40_Gomoko --exclude 36_Flip_Flop --exclude 43_Hammurabi --exclude 04_Awari --exclude 78_Sine_Wave --exclude 77_Salvo --exclude 34_Digits --exclude 17_Bullfight --exclude 16_Bug
|
mypy . --exclude 79_Slalom --exclude 27_Civil_War --exclude 38_Fur_Trader --exclude 81_Splat --exclude 09_Battle --exclude 40_Gomoko --exclude 36_Flip_Flop --exclude 43_Hammurabi --exclude 04_Awari --exclude 78_Sine_Wave --exclude 77_Salvo --exclude 34_Digits --exclude 17_Bullfight --exclude 16_Bug
|
||||||
- name: Test with flake8
|
- name: Test with flake8
|
||||||
run: |
|
run: |
|
||||||
flake8 . --ignore E501,W504,W503,F541,E203,W291,E711,F821,F401,E402,E731
|
flake8 . --ignore E501,W503,E203,E731
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from amazing import build_maze, welcome_header
|
|||||||
|
|
||||||
|
|
||||||
def test_welcome_header(capsys):
|
def test_welcome_header(capsys):
|
||||||
assert welcome_header() == None
|
assert welcome_header() is None
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert out == (
|
assert out == (
|
||||||
" AMAZING PROGRAM\n"
|
" AMAZING PROGRAM\n"
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def main() -> None:
|
|||||||
sea = tuple([0 for _ in range(SEA_WIDTH)] for _ in range(SEA_WIDTH))
|
sea = tuple([0 for _ in range(SEA_WIDTH)] for _ in range(SEA_WIDTH))
|
||||||
setup_ships(sea)
|
setup_ships(sea)
|
||||||
print(
|
print(
|
||||||
f"""
|
"""
|
||||||
BATTLE
|
BATTLE
|
||||||
CREATIVE COMPUTING MORRISTOWN, NEW JERSEY
|
CREATIVE COMPUTING MORRISTOWN, NEW JERSEY
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ def update_game(data, action):
|
|||||||
# the new part depends on and doesn't have enough of the part already
|
# the new part depends on and doesn't have enough of the part already
|
||||||
overMaxParts = part_type.count < part_count + 1
|
overMaxParts = part_type.count < part_count + 1
|
||||||
missingPartDep = (
|
missingPartDep = (
|
||||||
part_type.depends != None and parts[part_type.depends] == 0
|
part_type.depends is not None and parts[part_type.depends] == 0
|
||||||
)
|
)
|
||||||
|
|
||||||
if not overMaxParts and not missingPartDep:
|
if not overMaxParts and not missingPartDep:
|
||||||
|
|||||||
@@ -190,20 +190,21 @@ def main():
|
|||||||
union_strategy_index = 0
|
union_strategy_index = 0
|
||||||
u = 0
|
u = 0
|
||||||
u2 = 0
|
u2 = 0
|
||||||
|
random_nb = 0
|
||||||
while True:
|
while True:
|
||||||
print()
|
print()
|
||||||
print()
|
print()
|
||||||
print()
|
print()
|
||||||
a = int(input("WHICH BATTLE DO YOU WISH TO SIMULATE? "))
|
simulated_battle_index = int(input("WHICH BATTLE DO YOU WISH TO SIMULATE? "))
|
||||||
if a < 1 or a > 14:
|
if simulated_battle_index < 1 or simulated_battle_index > 14:
|
||||||
break
|
break
|
||||||
if a != 0 or r == 0:
|
if simulated_battle_index != 0 or random_nb == 0:
|
||||||
cs = historical_data[a][0]
|
cs = historical_data[simulated_battle_index][0]
|
||||||
m1 = historical_data[a][1]
|
m1 = historical_data[simulated_battle_index][1]
|
||||||
m2 = historical_data[a][2]
|
m2 = historical_data[simulated_battle_index][2]
|
||||||
c1 = historical_data[a][3]
|
c1 = historical_data[simulated_battle_index][3]
|
||||||
c2 = historical_data[a][4]
|
c2 = historical_data[simulated_battle_index][4]
|
||||||
m = historical_data[a][5]
|
m = historical_data[simulated_battle_index][5]
|
||||||
u = 0
|
u = 0
|
||||||
# Inflation calc
|
# Inflation calc
|
||||||
i1 = 10 + (line - w) * 2
|
i1 = 10 + (line - w) * 2
|
||||||
@@ -228,7 +229,7 @@ def main():
|
|||||||
print()
|
print()
|
||||||
print(f"THIS IS THE BATTLE OF {cs}")
|
print(f"THIS IS THE BATTLE OF {cs}")
|
||||||
if xs != "NO":
|
if xs != "NO":
|
||||||
print("\n".join(battles[a - 1]))
|
print("\n".join(battles[simulated_battle_index - 1]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(cs + " INSTANT REPLAY")
|
print(cs + " INSTANT REPLAY")
|
||||||
@@ -318,7 +319,7 @@ def main():
|
|||||||
print("THE CONFEDERACY HAS SURRENDERED.")
|
print("THE CONFEDERACY HAS SURRENDERED.")
|
||||||
break
|
break
|
||||||
# Union strategy is computer chosen
|
# Union strategy is computer chosen
|
||||||
if a == 0:
|
if simulated_battle_index == 0:
|
||||||
while True:
|
while True:
|
||||||
union_strategy_index = int(input("UNION STRATEGY IS "))
|
union_strategy_index = int(input("UNION STRATEGY IS "))
|
||||||
if union_strategy_index > 0 and union_strategy_index < 5:
|
if union_strategy_index > 0 and union_strategy_index < 5:
|
||||||
@@ -326,12 +327,12 @@ def main():
|
|||||||
print("ENTER 1, 2, 3, OR 4 (USUALLY PREVIOUS UNION STRATEGY)")
|
print("ENTER 1, 2, 3, OR 4 (USUALLY PREVIOUS UNION STRATEGY)")
|
||||||
else:
|
else:
|
||||||
s0 = 0
|
s0 = 0
|
||||||
r = math.random() * 100
|
random_nb = math.random() * 100
|
||||||
for i in range(1, 5):
|
for i in range(1, 5):
|
||||||
s0 += sa[i]
|
s0 += sa[i]
|
||||||
# If actual strategy info is in program data statements
|
# If actual strategy info is in program data statements
|
||||||
# then r-100 is extra weight given to that strategy.
|
# then r-100 is extra weight given to that strategy.
|
||||||
if r < s0:
|
if random_nb < s0:
|
||||||
break
|
break
|
||||||
union_strategy_index = i
|
union_strategy_index = i
|
||||||
print(union_strategy_index)
|
print(union_strategy_index)
|
||||||
@@ -347,7 +348,7 @@ def main():
|
|||||||
print("YOUR STRATEGY ? ", end="")
|
print("YOUR STRATEGY ? ", end="")
|
||||||
if i == 2:
|
if i == 2:
|
||||||
union_strategy_index = strategy_index
|
union_strategy_index = strategy_index
|
||||||
strategy_index = previous_strategy
|
strategy_index = previous_strategy # noqa: F821
|
||||||
if union_strategy_index != 5:
|
if union_strategy_index != 5:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -407,15 +408,15 @@ def main():
|
|||||||
w0 += 1
|
w0 += 1
|
||||||
elif u == 1 or (u != 1 and u2 != 1 and c5 + e > c6 + e2):
|
elif u == 1 or (u != 1 and u2 != 1 and c5 + e > c6 + e2):
|
||||||
print("THE UNION WINS " + str(cs))
|
print("THE UNION WINS " + str(cs))
|
||||||
if a != 0:
|
if simulated_battle_index != 0:
|
||||||
line += 1
|
line += 1
|
||||||
else:
|
else:
|
||||||
print("THE CONFEDERACY WINS " + str(cs))
|
print("THE CONFEDERACY WINS " + str(cs))
|
||||||
if a != 0:
|
if simulated_battle_index != 0:
|
||||||
w += 1
|
w += 1
|
||||||
|
|
||||||
# Lines 2530 to 2590 from original are unreachable.
|
# Lines 2530 to 2590 from original are unreachable.
|
||||||
if a != 0:
|
if simulated_battle_index != 0:
|
||||||
t1 += c5 + e
|
t1 += c5 + e
|
||||||
t2 += c6 + e2
|
t2 += c6 + e2
|
||||||
p1 += c1
|
p1 += c1
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ while play_again:
|
|||||||
play_again = m == "5"
|
play_again = m == "5"
|
||||||
|
|
||||||
if winnings < 0:
|
if winnings < 0:
|
||||||
print(f"Too bad, you are in the hole. Come again.")
|
print("Too bad, you are in the hole. Come again.")
|
||||||
elif winnings > 0:
|
elif winnings > 0:
|
||||||
print(f"Congratulations---you came out a winner. Come again.")
|
print("Congratulations---you came out a winner. Come again.")
|
||||||
else:
|
else:
|
||||||
print(f"Congratulations---you came out even, not bad for an amateur")
|
print("Congratulations---you came out even, not bad for an amateur")
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ def get_shot_input():
|
|||||||
x, y, z = raw_guess.split()
|
x, y, z = raw_guess.split()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Please enter coordinates separated by spaces")
|
print("Please enter coordinates separated by spaces")
|
||||||
print(f"Example: 3 2 1")
|
print("Example: 3 2 1")
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
x, y, z = (int(num) for num in [x, y, z])
|
x, y, z = (int(num) for num in [x, y, z])
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
# more structured style.
|
# more structured style.
|
||||||
#
|
#
|
||||||
|
|
||||||
import random
|
|
||||||
|
|
||||||
# global variables
|
# global variables
|
||||||
marbles_in_middle = -1
|
marbles_in_middle = -1
|
||||||
human_marbles = -1
|
human_marbles = -1
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ if __name__ == "__main__":
|
|||||||
beaver_price = (
|
beaver_price = (
|
||||||
int((0.25 * random.random() + 1.00) * 100 + 0.5) / 100
|
int((0.25 * random.random() + 1.00) * 100 + 0.5) / 100
|
||||||
) # INT((.25*RND(1)+1.00)*10^2+.5)/10^2
|
) # INT((.25*RND(1)+1.00)*10^2+.5)/10^2
|
||||||
if fox_price == None:
|
if fox_price is None:
|
||||||
# Original Bug? There is no Fox price generated for New York, it will use any previous "D1" price
|
# Original Bug? There is no Fox price generated for New York, it will use any previous "D1" price
|
||||||
# So if there was no previous value, make one up
|
# So if there was no previous value, make one up
|
||||||
fox_price = (
|
fox_price = (
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import random
|
import random
|
||||||
from typing import List, Tuple
|
from typing import Any, List, Tuple
|
||||||
|
|
||||||
|
|
||||||
def print_n_whitespaces(n: int) -> None:
|
def print_n_whitespaces(n: int) -> None:
|
||||||
print(" " * n, end="")
|
print(" " * n, end="")
|
||||||
|
|
||||||
|
|
||||||
def print_board():
|
def print_board(A: List[List[Any]], n):
|
||||||
"""PRINT THE BOARD"""
|
"""PRINT THE BOARD"""
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
print(" ", end="")
|
print(" ", end="")
|
||||||
@@ -128,7 +128,7 @@ def main():
|
|||||||
and board[X - 1][Y - 1] == 0
|
and board[X - 1][Y - 1] == 0
|
||||||
):
|
):
|
||||||
board[X - 1][Y - 1] = 2
|
board[X - 1][Y - 1] = 2
|
||||||
print_board()
|
print_board(board, n)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if board[X - 1][Y - 1] != 0:
|
if board[X - 1][Y - 1] != 0:
|
||||||
@@ -140,11 +140,11 @@ def main():
|
|||||||
and board[X - 1][Y - 1] == 0
|
and board[X - 1][Y - 1] == 0
|
||||||
):
|
):
|
||||||
board[X - 1][Y - 1] = 2
|
board[X - 1][Y - 1] = 2
|
||||||
print_board()
|
print_board(board, n)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
board[X - 1][Y - 1] = 2
|
board[X - 1][Y - 1] = 2
|
||||||
print_board()
|
print_board(board, n)
|
||||||
print()
|
print()
|
||||||
print("THANKS FOR THE GAME!!")
|
print("THANKS FOR THE GAME!!")
|
||||||
repeat = input("PLAY AGAIN (1 FOR YES, 0 FOR NO)? ")
|
repeat = input("PLAY AGAIN (1 FOR YES, 0 FOR NO)? ")
|
||||||
|
|||||||
@@ -73,16 +73,16 @@ def solve_sex_problem(user_name):
|
|||||||
valid, too_much = prompt_too_much_or_too_little()
|
valid, too_much = prompt_too_much_or_too_little()
|
||||||
if valid:
|
if valid:
|
||||||
if too_much:
|
if too_much:
|
||||||
print(f"YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!")
|
print("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!")
|
||||||
print(f"IF IT BOTHERS YOU, {user_name}, TAKE A COLD SHOWER.")
|
print(f"IF IT BOTHERS YOU, {user_name}, TAKE A COLD SHOWER.")
|
||||||
else:
|
else:
|
||||||
print(f"WHY ARE YOU HERE IN SUFFERN, {user_name}? YOU SHOULD BE")
|
print(f"WHY ARE YOU HERE IN SUFFERN, {user_name}? YOU SHOULD BE")
|
||||||
print(f"IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME")
|
print("IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME")
|
||||||
print(f"REAL ACTION.")
|
print("REAL ACTION.")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print(f"DON'T GET ALL SHOOK, {user_name}, JUST ANSWER THE QUESTION")
|
print(f"DON'T GET ALL SHOOK, {user_name}, JUST ANSWER THE QUESTION")
|
||||||
print(f"WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT?")
|
print("WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT?")
|
||||||
|
|
||||||
|
|
||||||
def solve_money_problem(user_name):
|
def solve_money_problem(user_name):
|
||||||
@@ -140,7 +140,7 @@ def ask_question_loop(user_name):
|
|||||||
def ask_for_fee(user_name):
|
def ask_for_fee(user_name):
|
||||||
print()
|
print()
|
||||||
print(f"THAT WILL BE $5.00 FOR THE ADVICE, {user_name}.")
|
print(f"THAT WILL BE $5.00 FOR THE ADVICE, {user_name}.")
|
||||||
print(f"PLEASE LEAVE THE MONEY ON THE TERMINAL.")
|
print("PLEASE LEAVE THE MONEY ON THE TERMINAL.")
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
print()
|
print()
|
||||||
print()
|
print()
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ Ported by Dave LeCompte
|
|||||||
# state. This adaptation pulls things apart into phrases, but I have
|
# state. This adaptation pulls things apart into phrases, but I have
|
||||||
# left the variables as globals, which makes goes against decades of
|
# left the variables as globals, which makes goes against decades of
|
||||||
# wisdom that global state is bad.
|
# wisdom that global state is bad.
|
||||||
|
import random
|
||||||
|
|
||||||
PAGE_WIDTH = 64
|
PAGE_WIDTH = 64
|
||||||
|
|
||||||
import random
|
|
||||||
|
|
||||||
# globals
|
# globals
|
||||||
u = 0
|
u = 0
|
||||||
|
|||||||
@@ -919,7 +919,7 @@ def end_game(won=False, quit=True, enterprise_killed=False):
|
|||||||
print(f"IT IS STARDATE {round(t, 1)}")
|
print(f"IT IS STARDATE {round(t, 1)}")
|
||||||
|
|
||||||
print(f"THERE WERE {k9} KLINGON BATTLE CRUISERS LEFT AT")
|
print(f"THERE WERE {k9} KLINGON BATTLE CRUISERS LEFT AT")
|
||||||
print(f"THE END OF YOUR MISSION.\n\n")
|
print("THE END OF YOUR MISSION.\n\n")
|
||||||
|
|
||||||
if b9 == 0:
|
if b9 == 0:
|
||||||
exit()
|
exit()
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ Weapon targeting simulation / 3d trigonometry practice
|
|||||||
Ported by Dave LeCompte
|
Ported by Dave LeCompte
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import collections
|
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
|
|
||||||
@@ -129,9 +128,9 @@ def do_shot_loop(p1, x, y, z):
|
|||||||
print()
|
print()
|
||||||
print(" * * * HIT * * * TARGET IS NON FUNCTIONAL")
|
print(" * * * HIT * * * TARGET IS NON FUNCTIONAL")
|
||||||
print()
|
print()
|
||||||
print(f"DISTANCE OF EXPLOSION FROM TARGET WAS {d:.4f} KILOMETERS")
|
print(f"DISTANCE OF EXPLOSION FROM TARGET WAS {distance:.4f} KILOMETERS")
|
||||||
print()
|
print()
|
||||||
print(f"MISSION ACCOMPLISHED IN {r} SHOTS.")
|
print(f"MISSION ACCOMPLISHED IN {shot_count} SHOTS.")
|
||||||
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -205,13 +205,13 @@ class TicTacToe3D:
|
|||||||
return event(i)
|
return event(i)
|
||||||
|
|
||||||
m = self.markAndMove(80, 88, 43)
|
m = self.markAndMove(80, 88, 43)
|
||||||
if m != None:
|
if m is not None:
|
||||||
return m
|
return m
|
||||||
|
|
||||||
self.clearStrategyMarks()
|
self.clearStrategyMarks()
|
||||||
|
|
||||||
m = self.markAndMove(16, 24, 11)
|
m = self.markAndMove(16, 24, 11)
|
||||||
if m != None:
|
if m is not None:
|
||||||
return m
|
return m
|
||||||
|
|
||||||
for k in range(18):
|
for k in range(18):
|
||||||
@@ -223,7 +223,7 @@ class TicTacToe3D:
|
|||||||
for s in [1, 0]:
|
for s in [1, 0]:
|
||||||
for i in range(4 * k, 4 * k + 4):
|
for i in range(4 * k, 4 * k + 4):
|
||||||
m = self.moveDiagonals(i, s)
|
m = self.moveDiagonals(i, s)
|
||||||
if m != None:
|
if m is not None:
|
||||||
return m
|
return m
|
||||||
|
|
||||||
self.clearStrategyMarks()
|
self.clearStrategyMarks()
|
||||||
|
|||||||
@@ -117,13 +117,13 @@ def think(board, g, h, moves):
|
|||||||
|
|
||||||
if g == OccupiedBy.PLAYER:
|
if g == OccupiedBy.PLAYER:
|
||||||
j = 3 * int((moves - 1) / 3)
|
j = 3 * int((moves - 1) / 3)
|
||||||
if move == j + 1:
|
if move == j + 1: # noqa: This definitely is a bug!
|
||||||
k = 1
|
k = 1
|
||||||
if move == j + 2:
|
if move == j + 2: # noqa: This definitely is a bug!
|
||||||
k = 2
|
k = 2
|
||||||
if move == j + 3:
|
if move == j + 3: # noqa: This definitely is a bug!
|
||||||
k = 3
|
k = 3
|
||||||
return subthink(g, h, j, k)
|
return subthink(g, h, j, k) # noqa: This definitely is a bug!
|
||||||
|
|
||||||
|
|
||||||
def render_board(board, space_mapping):
|
def render_board(board, space_mapping):
|
||||||
|
|||||||
Reference in New Issue
Block a user