mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Python: Fix Flake8 issue E712 + PEP8 variable naming
This commit is contained in:
@@ -115,38 +115,38 @@ def update_game(data, action):
|
||||
if "pictures" == action:
|
||||
data["state"] = "pictures"
|
||||
else:
|
||||
partAdded = False
|
||||
while partAdded == False:
|
||||
part_added = False
|
||||
while not part_added:
|
||||
for player, parts in data["players"].items():
|
||||
# rolls the dice for a part
|
||||
newPartIdx = randint(1, 6) - 1
|
||||
new_part_idx = randint(1, 6) - 1
|
||||
|
||||
# gets information about the picked part
|
||||
partType = data["partTypes"][newPartIdx]
|
||||
part_type = data["partTypes"][new_part_idx]
|
||||
|
||||
# gets the number of existing parts of that type the player has
|
||||
partCount = parts[newPartIdx]
|
||||
part_count = parts[new_part_idx]
|
||||
|
||||
logs.append(("rolled", newPartIdx, player))
|
||||
logs.append(("rolled", new_part_idx, player))
|
||||
|
||||
# a new part can only be added if the player has the parts
|
||||
# the new part depends on and doesn't have enough of the part already
|
||||
overMaxParts = partType.count < partCount + 1
|
||||
overMaxParts = part_type.count < part_count + 1
|
||||
missingPartDep = (
|
||||
partType.depends != None and parts[partType.depends] == 0
|
||||
part_type.depends != None and parts[part_type.depends] == 0
|
||||
)
|
||||
|
||||
if not overMaxParts and not missingPartDep:
|
||||
# adds a new part
|
||||
partCount += 1
|
||||
logs.append(("added", newPartIdx, player))
|
||||
partAdded = True
|
||||
part_count += 1
|
||||
logs.append(("added", new_part_idx, player))
|
||||
part_added = True
|
||||
elif missingPartDep:
|
||||
logs.append(("missingDep", newPartIdx, player, partType.depends))
|
||||
logs.append(("missingDep", new_part_idx, player, part_type.depends))
|
||||
if overMaxParts:
|
||||
logs.append(("overMax", newPartIdx, player, partCount))
|
||||
logs.append(("overMax", new_part_idx, player, part_count))
|
||||
|
||||
data["players"][player][newPartIdx] = partCount
|
||||
data["players"][player][new_part_idx] = part_count
|
||||
data["logs"] = logs
|
||||
|
||||
# checks if any players have finished their bug
|
||||
@@ -162,10 +162,10 @@ def get_finished(data):
|
||||
"""
|
||||
Gets players who have finished their bugs
|
||||
"""
|
||||
totalParts = sum(partType.count for partType in data["partTypes"])
|
||||
total_parts = sum(part_type.count for part_type in data["partTypes"])
|
||||
finished = []
|
||||
for player, parts in data["players"].items():
|
||||
if sum(parts) == totalParts:
|
||||
if sum(parts) == total_parts:
|
||||
finished.append(player)
|
||||
return finished
|
||||
|
||||
@@ -175,34 +175,34 @@ def print_game(data):
|
||||
Displays the results of the game turn
|
||||
"""
|
||||
for log in data["logs"]:
|
||||
code, partIdx, player, *logdata = log
|
||||
partType = data["partTypes"][partIdx]
|
||||
code, part_idx, player, *logdata = log
|
||||
part_type = data["partTypes"][part_idx]
|
||||
|
||||
if "rolled" == code:
|
||||
print()
|
||||
print(f"{player} ROLLED A {partIdx + 1}")
|
||||
print(f"{partIdx + 1}={partType.name}")
|
||||
print(f"{player} ROLLED A {part_idx + 1}")
|
||||
print(f"{part_idx + 1}={part_type.name}")
|
||||
|
||||
elif "added" == code:
|
||||
if "YOU" == player:
|
||||
if partType.name in ["FEELERS", "LEGS", "TAIL"]:
|
||||
print(f"I NOW GIVE YOU A {partType.name.replace('s', '')}.")
|
||||
if part_type.name in ["FEELERS", "LEGS", "TAIL"]:
|
||||
print(f"I NOW GIVE YOU A {part_type.name.replace('s', '')}.")
|
||||
else:
|
||||
print(f"YOU NOW HAVE A {partType.name}.")
|
||||
print(f"YOU NOW HAVE A {part_type.name}.")
|
||||
elif "I" == player:
|
||||
if partType.name in ["BODY", "NECK", "TAIL"]:
|
||||
print(f"I NOW HAVE A {partType.name}.")
|
||||
elif partType.name == "FEELERS":
|
||||
if part_type.name in ["BODY", "NECK", "TAIL"]:
|
||||
print(f"I NOW HAVE A {part_type.name}.")
|
||||
elif part_type.name == "FEELERS":
|
||||
print("I GET A FEELER.")
|
||||
|
||||
if partType.count > 2:
|
||||
if part_type.count > 2:
|
||||
print(
|
||||
f"{player} NOW HAVE {data['players'][player][partIdx]} {partType.name}"
|
||||
f"{player} NOW HAVE {data['players'][player][part_idx]} {part_type.name}"
|
||||
)
|
||||
|
||||
elif "missingDep" == code:
|
||||
(depIdx,) = logdata
|
||||
dep = data["partTypes"][depIdx]
|
||||
(dep_idx,) = logdata
|
||||
dep = data["partTypes"][dep_idx]
|
||||
print(
|
||||
f"YOU DO NOT HAVE A {dep.name}"
|
||||
if "YOU" == player
|
||||
@@ -210,12 +210,12 @@ def print_game(data):
|
||||
)
|
||||
|
||||
elif "overMax" == code:
|
||||
(partCount,) = logdata
|
||||
if partCount > 1:
|
||||
num = "TWO" if 2 == partCount else partCount
|
||||
maxMsg = f"HAVE {num} {partType.name}S ALREADY"
|
||||
(part_count,) = logdata
|
||||
if part_count > 1:
|
||||
num = "TWO" if 2 == part_count else part_count
|
||||
maxMsg = f"HAVE {num} {part_type.name}S ALREADY"
|
||||
else:
|
||||
maxMsg = f"ALREADY HAVE A {partType.name}"
|
||||
maxMsg = f"ALREADY HAVE A {part_type.name}"
|
||||
print(f"{player} {maxMsg}")
|
||||
|
||||
return input("DO YOU WANT THE PICTURES? ") if len(data["logs"]) else "n"
|
||||
@@ -225,7 +225,7 @@ def print_pictures(data):
|
||||
"""
|
||||
Displays what the bugs look like for each player
|
||||
"""
|
||||
typeIxs = {partType.name: idx for idx, partType in enumerate(data["partTypes"])}
|
||||
typeIxs = {part_type.name: idx for idx, part_type in enumerate(data["partTypes"])}
|
||||
PIC_WIDTH = 22
|
||||
for player, parts in data["players"].items():
|
||||
print(f"*****{'YOUR' if 'YOU' == player else 'MY'} BUG*****")
|
||||
@@ -317,7 +317,7 @@ if __name__ == "__main__":
|
||||
}
|
||||
|
||||
# body part types used by the game to work out whether a player's body part can be added
|
||||
partTypes = (
|
||||
part_types = (
|
||||
Bodypart(name="BODY", count=1, depends=None),
|
||||
Bodypart(name="NECK", count=1, depends=0),
|
||||
Bodypart(name="HEAD", count=1, depends=1),
|
||||
@@ -330,8 +330,8 @@ if __name__ == "__main__":
|
||||
data = {
|
||||
"state": "start",
|
||||
"partNo": None,
|
||||
"players": {"YOU": [0] * len(partTypes), "I": [0] * len(partTypes)},
|
||||
"partTypes": partTypes,
|
||||
"players": {"YOU": [0] * len(part_types), "I": [0] * len(part_types)},
|
||||
"partTypes": part_types,
|
||||
"finished": [],
|
||||
"logs": [],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user