mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 15:16:33 -08:00
MAINT: Apply pre-commit
Remove byte-order-marker pre-commit check as there would be many adjustments necessary
This commit is contained in:
@@ -7,17 +7,65 @@ import random
|
||||
|
||||
|
||||
def card_value(input):
|
||||
return ["2", "3", "4", "5", "6", "7", "8",
|
||||
"9", "10", "J", "Q", "K", "A"].index(input.split("-")[1])
|
||||
return ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"].index(
|
||||
input.split("-")[1]
|
||||
)
|
||||
|
||||
|
||||
cards = ["S-2", "H-2", "C-2", "D-2", "S-3", "H-3", "C-3", "D-3",
|
||||
"S-4", "H-4", "C-4", "D-4", "S-5", "H-5", "C-5", "D-5",
|
||||
"S-6", "H-6", "C-6", "D-6", "S-7", "H-7", "C-7", "D-7",
|
||||
"S-8", "H-8", "C-8", "D-8", "S-9", "H-9", "C-9", "D-9",
|
||||
"S-10", "H-10", "C-10", "D-10", "S-J", "H-J", "C-J", "D-J",
|
||||
"S-Q", "H-Q", "C-Q", "D-Q", "S-K", "H-K", "C-K", "D-K",
|
||||
"S-A", "H-A", "C-A", "D-A"]
|
||||
cards = [
|
||||
"S-2",
|
||||
"H-2",
|
||||
"C-2",
|
||||
"D-2",
|
||||
"S-3",
|
||||
"H-3",
|
||||
"C-3",
|
||||
"D-3",
|
||||
"S-4",
|
||||
"H-4",
|
||||
"C-4",
|
||||
"D-4",
|
||||
"S-5",
|
||||
"H-5",
|
||||
"C-5",
|
||||
"D-5",
|
||||
"S-6",
|
||||
"H-6",
|
||||
"C-6",
|
||||
"D-6",
|
||||
"S-7",
|
||||
"H-7",
|
||||
"C-7",
|
||||
"D-7",
|
||||
"S-8",
|
||||
"H-8",
|
||||
"C-8",
|
||||
"D-8",
|
||||
"S-9",
|
||||
"H-9",
|
||||
"C-9",
|
||||
"D-9",
|
||||
"S-10",
|
||||
"H-10",
|
||||
"C-10",
|
||||
"D-10",
|
||||
"S-J",
|
||||
"H-J",
|
||||
"C-J",
|
||||
"D-J",
|
||||
"S-Q",
|
||||
"H-Q",
|
||||
"C-Q",
|
||||
"D-Q",
|
||||
"S-K",
|
||||
"H-K",
|
||||
"C-K",
|
||||
"D-K",
|
||||
"S-A",
|
||||
"H-A",
|
||||
"C-A",
|
||||
"D-A",
|
||||
]
|
||||
|
||||
|
||||
def play_game():
|
||||
@@ -31,18 +79,22 @@ def play_game():
|
||||
print()
|
||||
card_you = cards[round]
|
||||
card_computer = cards[round * 2]
|
||||
print("You:", card_you, " " * (8 - len(card_you)) +
|
||||
"Computer:", card_computer)
|
||||
print("You:", card_you, " " * (8 - len(card_you)) + "Computer:", card_computer)
|
||||
value_you = card_value(card_you)
|
||||
value_computer = card_value(card_computer)
|
||||
if value_you > value_computer:
|
||||
score_you += 1
|
||||
print("You win. You have", score_you,
|
||||
"and the computer has", score_computer)
|
||||
print(
|
||||
"You win. You have", score_you, "and the computer has", score_computer
|
||||
)
|
||||
elif value_computer > value_you:
|
||||
score_computer += 1
|
||||
print("The computer wins!!! You have", score_you,
|
||||
"and the computer has", score_computer)
|
||||
print(
|
||||
"The computer wins!!! You have",
|
||||
score_you,
|
||||
"and the computer has",
|
||||
score_computer,
|
||||
)
|
||||
else:
|
||||
print("Tie. No score change.")
|
||||
cards_left -= 2
|
||||
@@ -50,8 +102,12 @@ def play_game():
|
||||
if input("Do you want to continue ").lower().startswith("n"):
|
||||
break
|
||||
if cards_left == 0:
|
||||
print("\nWe have run out of cards. Final score: You:",
|
||||
score_you, "the computer:", score_computer)
|
||||
print(
|
||||
"\nWe have run out of cards. Final score: You:",
|
||||
score_you,
|
||||
"the computer:",
|
||||
score_computer,
|
||||
)
|
||||
print("\nThanks for playing. It was fun.")
|
||||
|
||||
|
||||
@@ -68,8 +124,7 @@ def main():
|
||||
keep_playing = True
|
||||
while keep_playing:
|
||||
play_game()
|
||||
keep_playing = input(
|
||||
"\nPlay again? (yes or no) ").lower().startswith("y")
|
||||
keep_playing = input("\nPlay again? (yes or no) ").lower().startswith("y")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user