Last active
October 27, 2024 23:01
-
-
Save StrangeRanger/f758125d7d80e8d9a9c7da26f63b5af6 to your computer and use it in GitHub Desktop.
rock_paper_scissors.py
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
#!/usr/bin/env python3 | |
# | |
# Reason For Creation: | |
# This little script was created because a math class required us to play rock paper | |
# scissors against someone to observe probability. I didn't have anyone to do it with | |
# at the time, so I created this. | |
# | |
# Version: v1.0.2 | |
# License: MIT License | |
# Copyright (c) 2020-2021 Hunter T. (StrangeRanger) | |
# | |
######################################################################################## | |
""" | |
A randomized rock paper scissors game for the purpose of observing probability. | |
""" | |
####[ Imports ]######################################################################### | |
from random import randint | |
####[ Variables ]####################################################################### | |
NUM_OF_GAMES = 50 | |
pa_score = 0 | |
pb_score = 0 | |
tie = 0 | |
####[ Main ]############################################################################ | |
## Perform "Rock, Paper, Scissors". | |
for i in range(NUM_OF_GAMES): | |
# ------------------------------------------------ | |
# | |
# Number outcomes and their item equivalent: | |
# 1 = Rock | |
# 2 = Scissors | |
# 3 = Paper | |
# | |
# - Order DOES matter (player 1, player 2) | (R,P) ≠ (P,R) | |
# - Duplicates allowed (this means that both players use the same item) | |
# - Total permutations/possible outcomes: 3^2 = 9 | |
# | |
# ------------------------------------------------ | |
# | |
# Player 1 | Player 2 | |
# Tie R = R Tie | |
# Winner R > S | |
# R < P Winner | |
# Tie S = S Tie | |
# Winner S > P | |
# S < R Winner | |
# Tie P = P Tie | |
# Winner P > R | |
# P < S Winner | |
# | |
# OR | |
# | |
# Player 1 | Player 2 | |
# Tie 1 = 1 Tie | |
# Winner 1 > 2 | |
# 1 < 3 Winner | |
# Tie 2 = 2 Tie | |
# Winner 2 > 3 | |
# 2 < 1 Winner | |
# Tie 3 = 3 Tie | |
# Winner 3 > 1 | |
# 3 < 2 Winner | |
# | |
# ------------------------------------------------ | |
pa = randint(1, 3) | |
pb = randint(1, 3) | |
print("Game: {}".format(i + 1)) | |
# {(R,R),(S,S),(P,P)} | |
if pa == pb: | |
tie += 1 | |
print("Tie!\n") | |
elif (pa == 1 and pb == 2) or (pa == 2 and pb == 3) or (pa == 3 and pb == 1): | |
pa_score += 1 | |
print("Player A won!\n") | |
else: | |
pb_score += 1 | |
print("Player B won!\n") | |
print( | |
"Games have been complete\nPlayer A score: {}\nPlayer B score: {}\nTies: {}".format( | |
pa_score, pb_score, tie | |
) | |
) |
Author
StrangeRanger
commented
Jun 7, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment