-
-
Save gnyman/7d20364b2bc8656cc1b3da930efcfe76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open the file and read the strategy guide | |
with open('strategy_guide.txt') as file: | |
strategy_guide = [line.strip() for line in file] | |
# Define the score for each shape | |
SHAPE_SCORES = {'R': 1, 'P': 2, 'S': 3} | |
# Define the score for each outcome | |
OUTCOME_SCORES = {'X': 0, 'Y': 3, 'Z': 6} | |
# Initialize the total score to 0 | |
total_score = 0 | |
# Loop through each pair of characters in the strategy guide | |
for guide in strategy_guide: | |
# Split the guide into two values | |
opponent_choice, our_choice = guide.split() | |
# Choose the shape that will allow us to achieve the desired outcome | |
if our_choice == 'X': | |
# We need to lose the round, so choose the shape that will lose to the opponent's shape | |
if opponent_choice == 'R': | |
# The opponent chose Rock, so we need to choose Scissors | |
our_shape = 'S' | |
elif opponent_choice == 'S': | |
# The opponent chose Scissors, so we need to choose Paper | |
our_shape = 'P' | |
else: | |
# The opponent chose Paper, so we need to choose Rock | |
our_shape = 'R' | |
elif our_choice == 'Y': | |
# We need to draw the round, so choose the shape that will draw with the opponent's shape | |
if opponent_choice == 'R': | |
# The opponent chose Rock, so we need to choose Rock | |
our_shape = 'R' | |
elif opponent_choice == 'S': | |
# The opponent chose Scissors, so we need to choose Scissors | |
our_shape = 'S' | |
else: | |
# The opponent chose Paper, so we need to choose Paper | |
our_shape = 'P' | |
else: | |
# We need to win the round, so choose the shape that will win against the opponent's shape | |
if opponent_choice == 'R': | |
# The opponent chose Rock, so we need to choose Paper | |
our_shape = 'P' | |
elif opponent_choice == 'S': | |
# The opponent chose Scissors, so we need to choose Rock | |
our_shape = 'R' | |
else: | |
# The opponent chose Paper, so we need to choose Scissors | |
our_shape = 'S' | |
# Calculate the score for the round | |
round_score = SHAPE_SCORES[our_shape] + OUTCOME_SCORES[our_choice] | |
# Add the score for the round to the total score | |
total_score += round_score | |
# Print the total score | |
print(total_score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment