Skip to content

Instantly share code, notes, and snippets.

@gnyman
Created December 3, 2022 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnyman/6dec4624b24fd23f2e1b0e20a5625724 to your computer and use it in GitHub Desktop.
Save gnyman/6dec4624b24fd23f2e1b0e20a5625724 to your computer and use it in GitHub Desktop.
# 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}
print(OUTCOME_SCORES)
# Initialize the total score to 0
total_score = 0
# Loop through each pair of characters in the strategy guide
for guide in strategy_guide:
print(guide)
# Split the guide into two values
opponent_choice, our_choice = guide.split()
# Calculate the outcome of the round
if (opponent_choice == 'R' and our_choice == 'S') or (opponent_choice == 'S' and our_choice == 'P') or (opponent_choice == 'P' and our_choice == 'R'):
# We lose the round
outcome = 'X'
elif (opponent_choice == 'R' and our_choice == 'P') or (opponent_choice == 'S' and our_choice == 'R') or (opponent_choice == 'P' and our_choice == 'S'):
# We win the round
outcome = 'Z'
else:
# The round is a draw
outcome = 'Y'
# Calculate the score for the round
print(our_choice)
print(outcome)
round_score = SHAPE_SCORES[our_choice] + OUTCOME_SCORES[outcome]
# 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