Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Scissors cuts Paper
- Paper covers Rock
- Rock crushes Lizard
- Lizard poisons Spock
- Spock smashes Scissors
- Scissors decapitates Lizard
- Lizard eats Paper
- Paper disproves Spock
- Spock vaporizes Rock
- Rock crushes Scissors
- '''
- from random import choice
- def check(alpha, beta):
- for rule in RULES:
- winner, verb, loser = rule
- if (alpha, beta) == (winner, loser):
- return alpha, ' '.join(rule)
- if (beta, alpha) == (winner, loser):
- return beta, ' '.join(rule)
- return "", "" # no winner
- RULES = [rule.split() for rule in __doc__.strip().split('\n')]
- OPTIONS = list({winner for winner, verb, loser in RULES}
- | {loser for winner, verb, loser in RULES})
- PROMPT = f"{', '.join(sorted(OPTIONS))} (return to quit): "
- widest = max(len(option) for option in OPTIONS)
- print('Rules of the game:')
- print(__doc__)
- print()
- print('Games keep going until you decide to quit by just entering return without a choice')
- print('Running totals for wins, loses, and ties are printed each round.')
- print()
- wins = loses = ties = 0
- while True:
- user = 'to choose'
- while user and user not in OPTIONS:
- user = input(PROMPT).strip().capitalize()
- if not user:
- break
- computer = choice(OPTIONS)
- winner, rule = check(user, computer)
- if not winner:
- result = 'tied'
- ties += 1
- elif user == winner:
- result = 'win'
- wins += 1
- else: # computer == winner
- result = 'lose'
- loses += 1
- print(f"{user:^{widest}} v. {computer:^{widest}} - {result:4}"
- f" [{wins:3} | {loses:3} | {ties:2}]"
- f" {rule}\n"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement